pkg

Package management for Alpine Linux via apk.

This module registers under Salt’s pkg virtual name and is loaded automatically on Alpine minions. Existing states such as pkg.installed and pkg.removed work without any changes to your state files.

Important

If Salt is not using this module on an Alpine minion (or you see an error such as ‘pkg.install’ is not available), see here.

Version strings

Alpine packages follow the version-revision convention, for example 3.3.2-r0. This is what list_pkgs(), version(), and related functions return.

Hyphenated package names such as py3-requests and ca-certificates are handled correctly throughout. The module identifies the boundary between name and version by locating the first dash-separated component that begins with a digit.

Known limitations

  • Installing a specific package version is not yet supported. The version component of any pkgs dict entry is accepted but silently ignored.

  • Package hold and pin operations are not yet implemented.

  • Repository management (adding, removing, or listing /etc/apk/repositories entries) is not yet implemented.

saltext.alpine.modules.apk.__virtual__()[source]

Confirm this module is running on an Alpine Linux distribution

saltext.alpine.modules.apk.version(*names, **kwargs)[source]

Returns a string representing the package version or an empty string if not installed. If more than one package name is specified, a dict of name/version pairs is returned.

CLI Example:

salt '*' pkg.version <package name>
salt '*' pkg.version <package1> <package2> <package3> ...
saltext.alpine.modules.apk.refresh_db(**kwargs)[source]

Updates the package list

  • True: Database updated successfully

  • False: Problem updating database

CLI Example:

salt '*' pkg.refresh_db
saltext.alpine.modules.apk.list_pkgs(versions_as_list=False, **kwargs)[source]

List the packages currently installed in a dict:

{'<package_name>': '<version>'}

CLI Example:

salt '*' pkg.list_pkgs
salt '*' pkg.list_pkgs versions_as_list=True
saltext.alpine.modules.apk.latest_version(*names, **kwargs)[source]

Return the latest version of the named package available for upgrade or installation. If more than one package name is specified, a dict of name/version pairs is returned.

If the latest version of a given package is already installed, an empty string will be returned for that package.

CLI Example:

salt '*' pkg.latest_version <package name>
salt '*' pkg.latest_version <package name>
salt '*' pkg.latest_version <package1> <package2> <package3> ...
saltext.alpine.modules.apk.install(name=None, refresh=False, pkgs=None, sources=None, **kwargs)[source]

Install the passed package, add refresh=True to update the apk database.

name

The name of the package to be installed. Note that this parameter is ignored if either “pkgs” or “sources” is passed. Additionally, please note that this option can only be used to install packages from a software repository. To install a package file manually, use the “sources” option.

CLI Example:

salt '*' pkg.install <package name>
refresh

Whether or not to refresh the package database before installing.

Multiple Package Installation Options:

pkgs

A list of packages to install from a software repository. Must be passed as a python list.

CLI Example:

salt '*' pkg.install pkgs='["foo", "bar"]'
sources

A list of .apk packages to install. Must be passed as a list of dicts, with the keys being package names, and the values being the source URI or local path to the package. Dependencies are automatically resolved and marked as auto-installed.

CLI Example:

salt '*' pkg.install sources='[{"foo": "salt://foo.apk"},{"bar": "salt://bar.apk"}]'

Returns a dict containing the new package names and versions:

{'<package>': {'old': '<old-version>',
               'new': '<new-version>'}}
saltext.alpine.modules.apk.purge(name=None, pkgs=None, **kwargs)[source]

Remove packages and their configuration files using apk del --purge.

name

The name of the package to be purged.

pkgs

A list of packages to purge. Must be passed as a python list. The name parameter will be ignored if this option is passed.

Returns a dict containing the changes.

CLI Example:

salt '*' pkg.purge <package name>
salt '*' pkg.purge pkgs='["foo", "bar"]'
saltext.alpine.modules.apk.remove(name=None, pkgs=None, purge=False, **kwargs)[source]

Remove packages using apk del.

name

The name of the package to be deleted.

Multiple Package Options:

pkgs

A list of packages to delete. Must be passed as a python list. The name parameter will be ignored if this option is passed.

Returns a dict containing the changes.

CLI Example:

salt '*' pkg.remove <package name>
salt '*' pkg.remove <package1>,<package2>,<package3>
salt '*' pkg.remove pkgs='["foo", "bar"]'
saltext.alpine.modules.apk.upgrade(name=None, pkgs=None, refresh=True, **kwargs)[source]

Upgrades all packages via apk upgrade or a specific package if name or pkgs is specified. Name is ignored if pkgs is specified

Returns a dict containing the changes.

{‘<package>’: {‘old’: ‘<old-version>’,

‘new’: ‘<new-version>’}}

CLI Example:

salt '*' pkg.upgrade
saltext.alpine.modules.apk.list_upgrades(refresh=True, **kwargs)[source]

List all available package upgrades.

CLI Example:

salt '*' pkg.list_upgrades
saltext.alpine.modules.apk.file_list(*packages, **kwargs)[source]

List the files that belong to a package as a flat list. Not specifying any packages will return a list of every file on the system’s package database (not generally recommended).

CLI Examples:

salt '*' pkg.file_list httpd
salt '*' pkg.file_list httpd postfix
salt '*' pkg.file_list
saltext.alpine.modules.apk.file_dict(*packages, **kwargs)[source]

List the files that belong to a package, grouped by package. Not specifying any packages will return a list of every file on the system’s package database (not generally recommended).

CLI Examples:

salt '*' pkg.file_dict httpd
salt '*' pkg.file_dict httpd postfix
salt '*' pkg.file_dict
saltext.alpine.modules.apk.owner(*paths, **kwargs)[source]

Return the name of the package that owns the file. Multiple file paths can be passed. Like pkg.version <salt.modules.apk.version, if a single path is passed, a string will be returned, and if multiple paths are passed, a dictionary of file/package name pairs will be returned.

If the file is not owned by a package, or is not present on the minion, then an empty string will be returned for that path.

CLI Example:

salt '*' pkg.owner /usr/bin/apachectl
salt '*' pkg.owner /usr/bin/apachectl /usr/bin/basename