salt.modules.aptpkg

Support for APT (Advanced Packaging Tool)

注解

For virtual package support, either the python-apt or dctrl-tools package must be installed.

For repository management, the python-apt package must be installed.

salt.modules.aptpkg.autoremove(list_only=False, purge=False)

2015.5.0 新版功能.

Remove packages not required by another package using apt-get autoremove.

list_only : False
Only retrieve the list of packages to be auto-removed, do not actually perform the auto-removal.
purge : False

Also remove package config data when autoremoving packages.

2015.8.0 新版功能.

CLI 范例:

salt '*' pkg.autoremove
salt '*' pkg.autoremove list_only=True
salt '*' pkg.autoremove purge=True
salt.modules.aptpkg.del_repo(repo, **kwargs)

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范例:

salt '*' pkg.del_repo "myrepo definition"
salt.modules.aptpkg.del_repo_key(name=None, **kwargs)

2015.8.0 新版功能.

Remove a repo key using apt-key del

name
Repo from which to remove the key. Unnecessary if keyid is passed.
keyid
The KeyID of the GPG key to remove
keyid_ppa : False

If set to True, the repo's GPG key ID will be looked up from ppa.launchpad.net and removed.

注解

Setting this option to True requires that the name param also be passed.

CLI范例:

salt '*' pkg.del_repo_key keyid=0123ABCD
salt '*' pkg.del_repo_key name='ppa:foo/bar' keyid_ppa=True
salt.modules.aptpkg.expand_repo_def(repokwargs)

Take a repository definition and expand it to the full pkg repository dict that can be used for comparison. This is a helper function to make the Debian/Ubuntu apt sources sane for comparison in the pkgrepo states.

There is no use to calling this function via the CLI.

salt.modules.aptpkg.file_dict(*packages)

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范例:

salt '*' pkg.file_list httpd
salt '*' pkg.file_list httpd postfix
salt '*' pkg.file_list
salt.modules.aptpkg.file_list(*packages)

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范例:

salt '*' pkg.file_list httpd
salt '*' pkg.file_list httpd postfix
salt '*' pkg.file_list
salt.modules.aptpkg.get_repo(repo, **kwargs)

Display a repo from the sources.list / sources.list.d

The repo passed in needs to be a complete repo entry.

CLI范例:

salt '*' pkg.get_repo "myrepo definition"
salt.modules.aptpkg.get_selections(pattern=None, state=None)

View package state from the dpkg database.

Returns a dict of dicts containing the state, and package names:

{'<host>':
    {'<state>': ['pkg1',
                 ...
                ]
    },
    ...
}

CLI 范例:

salt '*' pkg.get_selections
salt '*' pkg.get_selections 'python-*'
salt '*' pkg.get_selections state=hold
salt '*' pkg.get_selections 'openssh*' state=hold
salt.modules.aptpkg.hold(name=None, pkgs=None, sources=None, **kwargs)

2014.7.0 新版功能.

设置软件包为'hold'状态,意味着该软件包将不会更新。

name

软件包的名字, e.g., 'tmux'

CLI 范例:

salt '*' pkg.hold <package name>
pkgs

A list of packages to hold. Must be passed as a python list.

CLI 范例:

salt '*' pkg.hold pkgs='["foo", "bar"]'
salt.modules.aptpkg.info_installed(*names)

Return the information of the named package(s) installed on the system.

2015.8.1 新版功能.

names
The names of the packages for which to return information.

CLI example:

salt '*' pkg.info_installed <package1>
salt '*' pkg.info_installed <package1> <package2> <package3> ...
salt.modules.aptpkg.install(name=None, refresh=False, fromrepo=None, skip_verify=False, debconf=None, pkgs=None, sources=None, reinstall=False, **kwargs)

Install the passed package, add refresh=True to update the dpkg 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.

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 范例:

salt '*' pkg.install <package name>
refresh
Whether or not to refresh the package database before installing.
fromrepo
Specify a package repository to install from (e.g., apt-get -t unstable install somepackage)
skip_verify
Skip the GPG verification check (e.g., --allow-unauthenticated, or --force-bad-verify for install from package file).
debconf
Provide the path to a debconf answers file, processed before installation.
version
Install a specific version of the package, e.g. 1.2.3~0ubuntu0. Ignored if "pkgs" or "sources" is passed.
reinstall : False

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.

2015.8.0 新版功能.

Multiple Package Installation Options:

pkgs

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

CLI 范例:

salt '*' pkg.install pkgs='["foo", "bar"]'
salt '*' pkg.install pkgs='["foo", {"bar": "1.2.3-0ubuntu0"}]'
sources

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.

在 2014.7.0 版更改.

CLI 范例:

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

Passes --force-yes to the apt-get command. Don't use this unless you know what you're doing.

0.17.4 新版功能.

install_recommends

Whether to install the packages marked as recommended. Default is True.

2015.5.0 新版功能.

only_upgrade

Only upgrade the packages, if they are already installed. Default is False.

2015.5.0 新版功能.

force_conf_new

Always install the new version of any configuration files.

2015.8.0 新版功能.

Returns a dict containing the new package names and versions:

{'<package>': {'old': '<old-version>',
               'new': '<new-version>'}}
salt.modules.aptpkg.latest_version(*names, **kwargs)

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.

CLI 范例:

salt '*' pkg.latest_version <package name>
salt '*' pkg.latest_version <package name> fromrepo=unstable
salt '*' pkg.latest_version <package1> <package2> <package3> ...
salt.modules.aptpkg.list_pkgs(versions_as_list=False, removed=False, purge_desired=False, **kwargs)

List the packages currently installed in a dict:

{'<package_name>': '<version>'}
removed
If True, then only packages which have been removed (but not purged) will be returned.
purge_desired

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

在 2014.1.1 版更改: Packages in this state now correctly show up in the output of this function.

注解

External dependencies

Virtual package resolution requires the dctrl-tools package to be installed. Virtual packages will show a version of 1.

CLI 范例:

salt '*' pkg.list_pkgs
salt '*' pkg.list_pkgs versions_as_list=True
salt.modules.aptpkg.list_repos()

Lists all repos in the sources.list (and sources.lists.d) files

CLI 范例:

salt '*' pkg.list_repos
salt '*' pkg.list_repos disabled=True
salt.modules.aptpkg.list_upgrades(refresh=True, dist_upgrade=True)

List all available package upgrades.

refresh
Whether to refresh the package database before listing upgrades. Default: True.
dist_upgrade
Whether to list the upgrades using dist-upgrade vs upgrade. Default is to use dist-upgrade.

CLI 范例:

salt '*' pkg.list_upgrades
salt.modules.aptpkg.mod_repo(repo, saltenv='base', **kwargs)

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:

comps
a comma separated list of components for the repo, e.g. main
file
a file name to be used
keyserver
keyserver to get gpg key from
keyid
key id to load with the keyserver argument
key_url
URL to a GPG key to add to the APT GPG keyring
consolidate
if True, will attempt to de-dup and consolidate sources

注解

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范例:

salt '*' pkg.mod_repo 'myrepo definition' uri=http://new/uri
salt '*' pkg.mod_repo 'myrepo definition' comps=main,universe
salt.modules.aptpkg.owner(*paths)

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 范例:

salt '*' pkg.owner /usr/bin/apachectl
salt '*' pkg.owner /usr/bin/apachectl /usr/bin/basename
salt.modules.aptpkg.purge(name=None, pkgs=None, **kwargs)

Remove packages via apt-get purge along with all configuration files.

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.

0.16.0 新版功能.

Returns a dict containing the changes.

CLI 范例:

salt '*' pkg.purge <package name>
salt '*' pkg.purge <package1>,<package2>,<package3>
salt '*' pkg.purge pkgs='["foo", "bar"]'
salt.modules.aptpkg.refresh_db()

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

CLI 范例:

salt '*' pkg.refresh_db
salt.modules.aptpkg.remove(name=None, pkgs=None, **kwargs)

Remove packages using apt-get remove.

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.

0.16.0 新版功能.

Returns a dict containing the changes.

CLI 范例:

salt '*' pkg.remove <package name>
salt '*' pkg.remove <package1>,<package2>,<package3>
salt '*' pkg.remove pkgs='["foo", "bar"]'
salt.modules.aptpkg.set_selections(path=None, selection=None, clear=False, saltenv='base')

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 范例:

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
salt.modules.aptpkg.unhold(name=None, pkgs=None, sources=None, **kwargs)

2014.7.0 新版功能.

Set package current in 'hold' state to install state, meaning it will be upgraded.

name

软件包的名字, e.g., 'tmux'

CLI 范例:

salt '*' pkg.unhold <package name>
pkgs

A list of packages to hold. Must be passed as a python list.

CLI 范例:

salt '*' pkg.unhold pkgs='["foo", "bar"]'
salt.modules.aptpkg.upgrade(refresh=True, dist_upgrade=False, **kwargs)

Upgrades all packages via apt-get upgrade or apt-get dist-upgrade if dist_upgrade is True.

Returns a dict containing the changes:

{'<package>':  {'old': '<old-version>',
                'new': '<new-version>'}}
dist_upgrade

Whether to perform the upgrade using dist-upgrade vs upgrade. Default is to use upgrade.

2014.7.0 新版功能.

force_conf_new

Always install the new version of any configuration files.

2015.8.0 新版功能.

CLI 范例:

salt '*' pkg.upgrade
salt.modules.aptpkg.upgrade_available(name)

Check whether or not an upgrade is available for a given package

CLI 范例:

salt '*' pkg.upgrade_available <package name>
salt.modules.aptpkg.version(*names, **kwargs)

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 范例:

salt '*' pkg.version <package name>
salt '*' pkg.version <package1> <package2> <package3> ...
salt.modules.aptpkg.version_cmp(pkg1, pkg2)

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.

CLI 范例:

salt '*' pkg.version_cmp '0.2.4-0ubuntu1' '0.2.4.1-0ubuntu1'