Yum

Manage yum packages and repositories. Note that yum package names are case-sensitive.

yum.key

Add yum gpg keys with rpm.

yum.key(key)
  • key: filename or URL

Note:

always returns one command, not state checking

Example:

linux_id = host.fact.linux_distribution['release_meta'].get('ID')
yum.key(
    {'Add the Docker CentOS gpg key'},
    'https://download.docker.com/linux/{}/gpg'.format(linux_id),
)

yum.packages

Install/remove/update yum packages & updates.

yum.packages(
    packages=None, present=True, latest=False, update=False, clean=False, nobest=False,
    extra_install_args='', extra_uninstall_args=''
)
  • packages: list of packages to ensure

  • present: whether the packages should be installed

  • latest: whether to upgrade packages without a specified version

  • update: run yum update

  • clean: run yum clean

  • nobest: add the no best option to install

  • extra_install_args: additional arguments to the yum install command

  • extra_uninstall_args: additional arguments to the yum uninstall command

Versions:

Package versions can be pinned like yum: <pkg>-<version>

Examples:

# Update package list and install packages
yum.packages(
    {'Install Vim and Vim enhanced'},
    ['vim-enhanced', 'vim'],
    update=True,
)

# Install the latest versions of packages (always check)
yum.packages(
    {'Install latest Vim'},
    ['vim'],
    latest=True,
)

yum.repo

Add/remove/update yum repositories.

yum.repo(
    name, baseurl=None, present=True, description=None, enabled=True, gpgcheck=True,
    gpgkey=None
)
  • name: URL or name for the .repo file

  • baseurl: the baseurl of the repo (if name is not a URL)

  • present: whether the .repo file should be present

  • description: optional verbose description

  • enabled: whether this repo is enabled

  • gpgcheck: whether set gpgcheck=1

  • gpgkey: the URL to the gpg key for this repo

Baseurl/description/gpgcheck/gpgkey:

These are only valid when name is a filename (ie not a URL). This is for manual construction of repository files. Use a URL to download and install remote repository files.

Examples:

# Download a repository file
yum.rpm(
    {'Install Docker-CE repo via URL'},
    'https://download.docker.com/linux/centos/docker-ce.repo',
)

# Create the repository file from baseurl/etc
yum.repo(
    {'Add the Docker CentOS repo'},
    name='DockerCE',
    baseurl='https://download.docker.com/linux/centos/7/$basearch/stable',
)

yum.rpm

Add/remove .rpm file packages.

yum.rpm(source, present=True)
  • source: filename or URL of the .rpm package

  • present: whether ore not the package should exist on the system

URL sources with present=False:

If the .rpm file isn’t downloaded, pyinfra can’t remove any existing package as the file won’t exist until mid-deploy.

Example:

yum.rpm(
   {'Install EPEL rpm to enable EPEL repo'},
   'https://dl.fedoraproject.org/pub/epel/epel-release-latest-'
   '{{  host.fact.linux_distribution.major }}.noarch.rpm',
)

yum.update

Updates all yum packages.

yum.update()