Support for APT (Advanced Packaging Tool)
Important
If you feel that Salt should be using this module to manage packages on a minion, and it is using a different module (or gives an error similar to 'pkg.install' is not available), see here.
New in version 2017.7.0.
Add a repo key using apt-key add
.
path (str) -- The path of the key file to import.
text (str) -- The key data to import, in string form.
keyserver (str) -- The server to download the repo key specified by the keyid.
keyid (str) -- The key id of the repo key to add.
saltenv (str) -- The environment the key file resides in.
aptkey (bool) -- Use the binary apt-key.
keydir (str) -- The directory path to save keys. The default directory is /etc/apt/keyrings/ which is the recommended path for adding third party keys. This argument is only used when aptkey is False.
keyfile (str) -- The name of the key to add. This is only required when aptkey is False and you are using a keyserver. This argument is only used when aptkey is False.
A boolean representing whether the repo key was added.
Warning
The apt-key binary is deprecated and will last be available in Debian 11 and Ubuntu 22.04. It is recommended to use aptkey=False when using this module.
CLI Examples:
salt '*' pkg.add_repo_key 'salt://apt/sources/test.key'
salt '*' pkg.add_repo_key text="'$KEY1'"
salt '*' pkg.add_repo_key keyserver='keyserver.example' keyid='0000AAAA'
New in version 2015.5.0.
Remove packages not required by another package using apt-get
autoremove
.
Only retrieve the list of packages to be auto-removed, do not actually perform the auto-removal.
Also remove package config data when autoremoving packages.
New in version 2015.8.0.
CLI Example:
salt '*' pkg.autoremove
salt '*' pkg.autoremove list_only=True
salt '*' pkg.autoremove purge=True
This function is an alias of latest_version
.
Changed in version 3007.0.
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.
A specific repo can be requested using the
fromrepo
keyword argument.cache_valid_time
New in version 2016.11.0.
Skip refreshing the package database if refresh has already occurred within <value> seconds
CLI Example:
salt '*' pkg.latest_version <package name> salt '*' pkg.latest_version <package name> fromrepo=unstable salt '*' pkg.latest_version <package1> <package2> <package3> ...
Delete a repo from the sources.list / sources.list.d
If the .list file is in the sources.list.d directory and the file that the repo exists in does not contain any other repo configuration, the file itself will be deleted.
The repo passed in must be a fully formed repository definition string.
CLI Examples:
salt '*' pkg.del_repo "myrepo definition"
New in version 2015.8.0.
Remove a repo key using apt-key del
Repo from which to remove the key. Unnecessary if keyid
is passed.
The KeyID of the GPG key to remove
If set to True
, the repo's GPG key ID will be looked up from
ppa.launchpad.net and removed.
Note
Setting this option to True
requires that the name
param
also be passed.
Use the binary apt-key.
The directory path to save keys. The default directory is /etc/apt/keyrings/ which is the recommended path for adding third party keys.
Warning
The apt-key binary is deprecated and will last be available in Debian 11 and Ubuntu 22.04. It is recommended to use aptkey=False when using this module.
CLI Examples:
salt '*' pkg.del_repo_key keyid=0123ABCD
salt '*' pkg.del_repo_key name='ppa:foo/bar' keyid_ppa=True
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
List the files that belong to a 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_list httpd
salt '*' pkg.file_list httpd postfix
salt '*' pkg.file_list
Display a repo from the sources.list / sources.list.d
The repo passed in needs to be a complete repo entry.
CLI Examples:
salt '*' pkg.get_repo "myrepo definition"
New in version 2017.7.0.
List known repo key details. :param bool aptkey: Use the binary apt-key. :param str keydir: The directory path to save keys. The default directory is /etc/apt/keyrings/ which is the recommended path for adding third party keys. This argument is only used when aptkey is False.
A dictionary containing the repo keys.
CLI Examples:
salt '*' pkg.get_repo_keys
View package state from the dpkg database.
Returns a dict of dicts containing the state, and package names:
{'<host>':
{'<state>': ['pkg1',
...
]
},
...
}
CLI Example:
salt '*' pkg.get_selections
salt '*' pkg.get_selections 'python-*'
salt '*' pkg.get_selections state=hold
salt '*' pkg.get_selections 'openssh*' state=hold
New in version 2014.7.0.
Set package in 'hold' state, meaning it will not be upgraded.
The name of the package, e.g., 'tmux'
CLI Example:
salt '*' pkg.hold <package name>
A list of packages to hold. Must be passed as a python list.
CLI Example:
salt '*' pkg.hold pkgs='["foo", "bar"]'
Return the information of the named package(s) installed on the system.
New in version 2015.8.1.
The names of the packages for which to return information.
Whether to throw an exception if none of the packages are installed. Defaults to True.
New in version 2016.11.3.
CLI Example:
salt '*' pkg.info_installed <package1>
salt '*' pkg.info_installed <package1> <package2> <package3> ...
salt '*' pkg.info_installed <package1> failhard=false
Changed in version 2015.8.12,2016.3.3,2016.11.0: On minions running systemd>=205, systemd-run(1) is now used to
isolate commands which modify installed packages from the
salt-minion
daemon's control group. This is done to keep systemd
from killing any apt-get/dpkg commands spawned by Salt when the
salt-minion
service is restarted. (see KillMode
in the
systemd.kill(5) manpage for more information). If desired, usage of
systemd-run(1) can be suppressed by setting a config option
called systemd.scope
, with a value of
False
(no quotes).
Install the passed package, add refresh=True to update the dpkg database.
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.
32-bit packages can be installed on 64-bit systems by appending the
architecture designation (:i386
, etc.) to the end of the package
name.
CLI Example:
salt '*' pkg.install <package name>
Whether or not to refresh the package database before installing.
cache_valid_time
New in version 2016.11.0.
Skip refreshing the package database if refresh has already occurred within <value> seconds
Specify a package repository to install from
(e.g., apt-get -t unstable install somepackage
)
Skip the GPG verification check (e.g., --allow-unauthenticated
, or
--force-bad-verify
for install from package file).
Provide the path to a debconf answers file, processed before installation.
Install a specific version of the package, e.g. 1.2.3~0ubuntu0. Ignored if "pkgs" or "sources" is passed.
Changed in version 2018.3.0: version can now contain comparison operators (e.g. >1.2.3
,
<=2.0
, etc.)
Specifying reinstall=True will use apt-get install --reinstall
rather than simply apt-get install
for requested packages that are
already installed.
If a version is specified with the requested package, then apt-get
install --reinstall
will only be used if the installed version
matches the requested version.
New in version 2015.8.0.
Only used when the version of a package is specified using a comparison
operator (e.g. >4.1
). If set to True
, then the epoch will be
ignored when comparing the currently-installed version to the desired
version.
New in version 2018.3.0.
Multiple Package Installation Options:
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"]'
salt '*' pkg.install pkgs='["foo", {"bar": "1.2.3-0ubuntu0"}]'
A list of DEB 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.
32-bit packages can be installed on 64-bit systems by appending the
architecture designation (:i386
, etc.) to the end of the package
name.
Changed in version 2014.7.0.
CLI Example:
salt '*' pkg.install sources='[{"foo": "salt://foo.deb"},{"bar": "salt://bar.deb"}]'
Passes --force-yes
to the apt-get command. Don't use this unless
you know what you're doing.
New in version 0.17.4.
Whether to install the packages marked as recommended. Default is True.
New in version 2015.5.0.
Only upgrade the packages, if they are already installed. Default is False.
New in version 2015.5.0.
Always install the new version of any configuration files.
New in version 2015.8.0.
Returns a dict containing the new package names and versions:
{'<package>': {'old': '<old-version>',
'new': '<new-version>'}}
Changed in version 3007.0.
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.
A specific repo can be requested using the fromrepo
keyword argument.
cache_valid_time
New in version 2016.11.0.
Skip refreshing the package database if refresh has already occurred within <value> seconds
CLI Example:
salt '*' pkg.latest_version <package name>
salt '*' pkg.latest_version <package name> fromrepo=unstable
salt '*' pkg.latest_version <package1> <package2> <package3> ...
New in version 3000.
List prefetched packages downloaded by apt in the local disk.
operate on a different root directory.
CLI Example:
salt '*' pkg.list_downloaded
List the packages currently installed in a dict:
{'<package_name>': '<version>'}
If True
, then only packages which have been removed (but not
purged) will be returned.
If True
, then only packages which have been marked to be purged,
but can't be purged due to their status as dependencies for other
installed packages, will be returned. Note that these packages will
appear in installed
Changed in version 2014.1.1: Packages in this state now correctly show up in the output of this function.
CLI Example:
salt '*' pkg.list_pkgs
salt '*' pkg.list_pkgs versions_as_list=True
New in version 2017.7.0.
Returns all available packages. Optionally, package names (and name globs) can be passed and the results will be filtered to packages matching those names.
This function can be helpful in discovering the version or repo to specify
in a pkg.installed
state.
The return data will be a dictionary mapping package names to a list of version numbers, ordered from newest to oldest. For example:
{
'bash': ['4.3-14ubuntu1.1',
'4.3-14ubuntu1'],
'nginx': ['1.10.0-0ubuntu0.16.04.4',
'1.9.15-0ubuntu1']
}
CLI Examples:
salt '*' pkg.list_repo_pkgs
salt '*' pkg.list_repo_pkgs foo bar baz
Lists all repos in the sources.list (and sources.lists.d) files
CLI Example:
salt '*' pkg.list_repos
salt '*' pkg.list_repos disabled=True
List all available package upgrades.
Whether to refresh the package database before listing upgrades. Default: True.
cache_valid_time
New in version 2016.11.0.
Skip refreshing the package database if refresh has already occurred within <value> seconds
Whether to list the upgrades using dist-upgrade vs upgrade. Default is to use dist-upgrade.
CLI Example:
salt '*' pkg.list_upgrades
Modify one or more values for a repo. If the repo does not exist, it will
be created, so long as the definition is well formed. For Ubuntu the
ppa:<project>/repo
format is acceptable. ppa:
format can only be
used to create a new repository.
The following options are available to modify a repo definition:
A comma-separated list of supported architectures, e.g. amd64
If
this option is not set, all architectures (configured in the system)
will be used.
A comma separated list of components for the repo, e.g. main
A file name to be used
Keyserver to get gpg key from
Key ID or a list of key IDs to load with the keyserver
argument
URL to a GPG key to add to the APT GPG keyring
GPG key in string form to add to the APT GPG keyring
New in version 2018.3.0.
If True
, will attempt to de-duplicate and consolidate sources
Sometimes you want to supply additional information, but not as enabled configuration. All comments provided here will be joined into a single string and appended to the repo configuration with a comment marker (#) before it.
New in version 2015.8.9.
Enable or disable (True or False) refreshing of the apt package
database. The previous refresh_db
argument was deprecated in
favor of refresh`
. The refresh_db
argument will still
continue to work to ensure backwards compatibility, but please
change to using the preferred refresh
.
Note
Due to the way keys are stored for APT, there is a known issue where the key won't be updated unless another change is made at the same time. Keys should be properly added on initial configuration.
CLI Examples:
salt '*' pkg.mod_repo 'myrepo definition' uri=http://new/uri
salt '*' pkg.mod_repo 'myrepo definition' comps=main,universe
Strips the architecture from the specified package name, if necessary.
CLI Example:
salt '*' pkg.normalize_name zsh:amd64
New in version 2014.7.0.
Return the name of the package that owns the file. Multiple file paths can
be passed. Like pkg.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
Parse name and architecture from the specified package name.
CLI Example:
salt '*' pkg.parse_arch zsh:amd64
Changed in version 2015.8.12,2016.3.3,2016.11.0: On minions running systemd>=205, systemd-run(1) is now used to
isolate commands which modify installed packages from the
salt-minion
daemon's control group. This is done to keep systemd
from killing any apt-get/dpkg commands spawned by Salt when the
salt-minion
service is restarted. (see KillMode
in the
systemd.kill(5) manpage for more information). If desired, usage of
systemd-run(1) can be suppressed by setting a config option
called systemd.scope
, with a value of
False
(no quotes).
Remove packages via apt-get purge
along with all configuration files.
The name of the package to be deleted.
Multiple Package Options:
A list of packages to delete. Must be passed as a python list. The
name
parameter will be ignored if this option is passed.
New in version 0.16.0.
Returns a dict containing the changes.
CLI Example:
salt '*' pkg.purge <package name>
salt '*' pkg.purge <package1>,<package2>,<package3>
salt '*' pkg.purge pkgs='["foo", "bar"]'
Updates the APT database to latest packages based upon repositories
Returns a dict, with the keys being package databases and the values being the result of the update attempt. Values can be one of the following:
True
: Database updated successfully
False
: Problem updating database
None
: Database already up-to-date
cache_valid_time
New in version 2016.11.0.
Skip refreshing the package database if refresh has already occurred within <value> seconds
failhard
If False, return results of Err lines as
False
for the package database that encountered the error. If True, raise an error with a list of the package databases that encountered errors.
CLI Example:
salt '*' pkg.refresh_db
Changed in version 2015.8.12,2016.3.3,2016.11.0: On minions running systemd>=205, systemd-run(1) is now used to
isolate commands which modify installed packages from the
salt-minion
daemon's control group. This is done to keep systemd
from killing any apt-get/dpkg commands spawned by Salt when the
salt-minion
service is restarted. (see KillMode
in the
systemd.kill(5) manpage for more information). If desired, usage of
systemd-run(1) can be suppressed by setting a config option
called systemd.scope
, with a value of
False
(no quotes).
Remove packages using apt-get remove
.
The name of the package to be deleted.
Multiple Package Options:
A list of packages to delete. Must be passed as a python list. The
name
parameter will be ignored if this option is passed.
New in version 0.16.0.
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"]'
New in version 3003.
List services that use files which have been changed by the package manager. It might be needed to restart them.
Requires checkrestart from the debian-goodies package.
CLI Examples:
salt '*' pkg.services_need_restart
Change package state in the dpkg database.
The state can be any one of, documented in dpkg(1)
:
install
hold
deinstall
purge
This command is commonly used to mark specific packages to be held from
being upgraded, that is, to be kept at a certain version. When a state is
changed to anything but being held, then it is typically followed by
apt-get -u dselect-upgrade
.
Note: Be careful with the clear
argument, since it will start
with setting all packages to deinstall state.
Returns a dict of dicts containing the package names, and the new and old versions:
{'<host>':
{'<package>': {'new': '<new-state>',
'old': '<old-state>'}
},
...
}
CLI Example:
salt '*' pkg.set_selections selection='{"install": ["netcat"]}'
salt '*' pkg.set_selections selection='{"hold": ["openssh-server", "openssh-client"]}'
salt '*' pkg.set_selections salt://path/to/file
salt '*' pkg.set_selections salt://path/to/file clear=True
New in version 2019.2.0.
Runs an apt-cache show
on the passed package names, and returns the
results in a nested dictionary. The top level of the return data will be
the package name, with each package name mapping to a dictionary of version
numbers to any additional information returned by apt-cache show
.
An optional comma-separated list (or quoted Python list) of case-insensitive keys on which to filter. This allows one to restrict the information returned for each package to a smaller selection of pertinent items.
If True
, the apt cache will be refreshed first. By default, no
refresh is performed.
CLI Examples:
salt myminion pkg.show gawk
salt myminion pkg.show 'nginx-*'
salt myminion pkg.show 'nginx-*' filter=description,provides
New in version 2014.7.0.
Set package current in 'hold' state to install state, meaning it will be upgraded.
The name of the package, e.g., 'tmux'
CLI Example:
salt '*' pkg.unhold <package name>
A list of packages to unhold. Must be passed as a python list.
CLI Example:
salt '*' pkg.unhold pkgs='["foo", "bar"]'
Changed in version 2015.8.12,2016.3.3,2016.11.0: On minions running systemd>=205, systemd-run(1) is now used to
isolate commands which modify installed packages from the
salt-minion
daemon's control group. This is done to keep systemd
from killing any apt-get/dpkg commands spawned by Salt when the
salt-minion
service is restarted. (see KillMode
in the
systemd.kill(5) manpage for more information). If desired, usage of
systemd-run(1) can be suppressed by setting a config option
called systemd.scope
, with a value of
False
(no quotes).
Upgrades all packages via apt-get upgrade
or apt-get dist-upgrade
if dist_upgrade
is True
.
Returns a dictionary containing the changes:
{'<package>': {'old': '<old-version>',
'new': '<new-version>'}}
Whether to perform the upgrade using dist-upgrade vs upgrade. Default is to use upgrade.
New in version 2014.7.0.
If True
, the apt cache will be refreshed first. By default,
this is True
and a refresh is performed.
cache_valid_time
New in version 2016.11.0.
Skip refreshing the package database if refresh has already occurred within <value> seconds
Only download the packages, don't unpack or install them. Use downloadonly to be in line with yum and zypper module.
New in version 2018.3.0.
Always install the new version of any configuration files.
New in version 2015.8.0.
Allow apt to downgrade packages without a prompt.
New in version 3005.
CLI Example:
salt '*' pkg.upgrade
Check whether or not an upgrade is available for a given package
CLI Example:
salt '*' pkg.upgrade_available <package name>
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> ...
Do a cmp-style comparison on two packages. Return -1 if pkg1 < pkg2, 0 if pkg1 == pkg2, and 1 if pkg1 > pkg2. Return None if there was a problem making the comparison.
Set to True
to ignore the epoch when comparing versions
New in version 2015.8.10,2016.3.2.
CLI Example:
salt '*' pkg.version_cmp '0.2.4-0ubuntu1' '0.2.4.1-0ubuntu1'
Displays which package installed a specific file
CLI Examples:
salt * pkg.which <file name>