salt.states.pkg

Installation of packages using OS package managers such as yum or apt-get

Salt can manage software packages via the pkg state module, packages can be set up to be installed, latest, removed and purged. Package management declarations are typically rather simple:

vim:
  pkg.installed

A more involved example involves pulling from a custom repository. Note that the pkgrepo has a require_in clause. This is necessary and can not be replaced by a require clause in the pkg.

base:
  pkgrepo.managed:
    - humanname: Logstash PPA
    - name: deb http://ppa.launchpad.net/wolfnet/logstash/ubuntu precise main
    - dist: precise
    - file: /etc/apt/sources.list.d/logstash.list
    - keyid: 28B04E4A
    - keyserver: keyserver.ubuntu.com
    - require_in:
      - pkg: logstash

logstash:
  pkg.installed
salt.states.pkg.installed(name, version=None, refresh=False, fromrepo=None, skip_verify=False, pkgs=None, sources=None, **kwargs)

Verify that the package is installed, and that it is the correct version (if specified).

name
The name of the package to be installed. This parameter is ignored if either "pkgs" or "sources" is used. 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 detailed below.
fromrepo
Specify a repository from which to install
skip_verify
Skip the GPG verification check for the package to be installed
version
Install a specific version of a package. This option is ignored if either "pkgs" or "sources" is used. Currently, this option is supported for the following pkg providers: apt, ebuild, pacman, yumpkg, yumpkg5, and zypper.

Usage:

httpd:
  pkg.installed:
    - fromrepo: mycustomrepo
    - skip_verify: True
    - version: 2.0.6~ubuntu3

Multiple Package Installation Options: (not supported in Windows or pkgng)

pkgs
A list of packages to install from a software repository.

Usage:

mypkgs:
  pkg.installed:
    - pkgs:
      - foo
      - bar
      - baz

NOTE: For apt, ebuild, pacman, yumpkg, yumpkg5, and zypper, version numbers can be specified in the pkgs argument. Example:

mypkgs:
  pkg.installed:
    - pkgs:
      - foo
      - bar: 1.2.3-4
      - baz

Additionally, ebuild, pacman and zypper support the <, <=, >=, and > operators for more control over what versions will be installed. Example:

mypkgs:
  pkg.installed:
    - pkgs:
      - foo
      - bar: '>=1.2.3-4'
      - baz

NOTE: When using comparison operators, the expression must be enclosed in quotes to avoid a YAML render error.

With ebuild is also possible to specify a use flag list and/or if the given packages should be in package.accept_keywords file and/or the overlay from which you want the package to be installed. Example:

mypkgs:
    pkg.installed:
        - pkgs:
            - foo: '~'
            - bar: '~>=1.2:slot::overlay[use,-otheruse]'
            - baz
sources
A list of packages to install, along with the source URI or local path from which to install each package. In the example below, foo, bar, baz, etc. refer to the name of the package, as it would appear in the output of the pkg.version or pkg.list_pkgs salt CLI commands.

Usage:

mypkgs:
  pkg.installed:
    - sources:
      - foo: salt://rpms/foo.rpm
      - bar: http://somesite.org/bar.rpm
      - baz: ftp://someothersite.org/baz.rpm
      - qux: /minion/path/to/qux.rpm
salt.states.pkg.latest(name, refresh=False, fromrepo=None, skip_verify=False, pkgs=None, **kwargs)

Verify that the named package is installed and the latest available package. If the package can be updated this state function will update the package. Generally it is better for the installed function to be used, as latest will update the package whenever a new package is available.

name
The name of the package to maintain at the latest available version. This parameter is ignored if "pkgs" is used.
fromrepo
Specify a repository from which to install
skip_verify
Skip the GPG verification check for the package to be installed

Multiple Package Installation Options:

(Not yet supported for: Windows, FreeBSD, OpenBSD, MacOS, and Solaris pkgutil)

pkgs
A list of packages to maintain at the latest available version.

Usage:

mypkgs:
  pkg.latest:
    - pkgs:
      - foo
      - bar
      - baz
salt.states.pkg.purged(name, pkgs=None, **kwargs)

Verify that a package is not installed, calling pkg.purge if necessary to purge the package.

name
The name of the package to be purged.

Multiple Package Options:

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.

New in version 0.16.0.

salt.states.pkg.removed(name, pkgs=None, **kwargs)

Verify that a package is not installed, calling pkg.remove if necessary to remove the package.

name
The name of the package to be removed.

Multiple Package Options:

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

New in version 0.16.0.