apk – Manages apk packages — Ansible Documentation

- AnsibleFest
- Products
- Community
- Webinars & Training
- Blog

Documentation

# apk – Manages apk packages

- Synopsis
- Parameters
- Notes
- Examples
- Return Values
- Status

## Synopsis

- Manages apk packages for Alpine Linux.

## Parameters

Parameter | Choices/Defaults | Comments
--- | --- | ---
available boolean added in 2.4 | Choices: no ← yes | During upgrade, reset versioned world dependencies and change logic to prefer replacing or downgrading packages (instead of holding them) if the currently installed package is no longer available from any repository.
name - |  | A package name, like `foo`, or multiple packages, like `foo, bar`.
repository - added in 2.4 |  | A package repository or multiple repositories. Unlike with the underlying apk command, this list will override the system repositories rather than supplement them.
state - | Choices: present ← absent latest | Indicates the desired package(s) state. `present` ensures the package(s) is/are present. `absent` ensures the package(s) is/are absent. `latest` ensures the package(s) is/are present and the latest version(s).
update_cache boolean | Choices: no ← yes | Update repository indexes. Can be run with other steps or on it's own.
upgrade boolean | Choices: no ← yes | Upgrade all installed packages to their latest version.

## Notes

Note

- “name” and “upgrade” are mutually exclusive.
- When used with a loop: each package will be processed individually, it is much more efficient to pass the list directly to the name option.

## Examples

    # Update repositories and install "foo" package
    - apk:
        name: foo
        update_cache: yes

    # Update repositories and install "foo" and "bar" packages
    - apk:
        name: foo,bar
        update_cache: yes

    # Remove "foo" package
    - apk:
        name: foo
        state: absent

    # Remove "foo" and "bar" packages
    - apk:
        name: foo,bar
        state: absent

    # Install the package "foo"
    - apk:
        name: foo
        state: present

    # Install the packages "foo" and "bar"
    - apk:
        name: foo,bar
        state: present

    # Update repositories and update package "foo" to latest version
    - apk:
        name: foo
        state: latest
        update_cache: yes

    # Update repositories and update packages "foo" and "bar" to latest versions
    - apk:
        name: foo,bar
        state: latest
        update_cache: yes

    # Update all installed packages to the latest versions
    - apk:
        upgrade: yes

    # Upgrade / replace / downgrade / uninstall all installed packages to the latest versions available
    - apk:
        available: yes
        upgrade: yes

    # Update repositories as a separate step
    - apk:
        update_cache: yes

    # Install package from a specific repository
    - apk:
        name: foo
        state: latest
        update_cache: yes
        repository: http://dl-3.alpinelinux.org/alpine/edge/main

## Return Values

Common return values are documented here, the following are the fields unique to this module:

Key | Returned | Description
--- | --- | ---
packages list | when packages have changed | a list of packages that have been changed Sample: ['package', 'other-package']

## Status

- This module is guaranteed to have backward compatible interface changes going forward. [stableinterface]
- This module is maintained by the Ansible Community. [community]

### Authors

- Kevin Brebanov (@kbrebanov)

Hint

If you notice any issues in this documentation, you can edit this document to improve it.