yum Operations¶
Manage yum packages and repositories. Note that yum package names are case-sensitive.
Facts used in these operations: rpm.RpmPackageProvides, rpm.RpmPackages.
yum.key¶
Stateless operation
This operation will always execute commands and is not idempotent.
Add yum gpg keys with rpm.
- src: filename or URL
Note: always returns one command, not state checking
Example:
from pyinfra import host
from pyinfra.operations import dnf
from pyinfra.facts.server import LinuxDistribution
linux_id = host.get_fact(LinuxDistribution)["release_meta"].get("ID")
yum.key(
name="Add the Docker CentOS gpg key",
src=f"https://download.docker.com/linux/{linux_id}/gpg",
)
Global arguments
This operation also inherits all global arguments.
yum.packages¶
Install/remove/update yum packages & updates.
yum.packages(
packages: 'str | list[str] | None' = None,
present=True,
latest=False,
update=False,
clean=False,
nobest=False,
extra_install_args: 'str | None' = None,
extra_uninstall_args: 'str | None' = None,
**kwargs,
)
- 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 updatebefore installing packages - clean: run
yum clean allbefore installing packages - 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 as follows: <pkg>=<version>
Examples:
# Update package list and install packages
yum.packages(
name="Install Vim and Vim enhanced",
packages=["vim-enhanced", "vim"],
update=True,
)
# Install the latest versions of packages (always check)
yum.packages(
name="Install latest Vim",
packages=["vim"],
latest=True,
)
Global arguments
This operation also inherits all global arguments.
yum.repo¶
Add/remove/update yum repositories.
yum.repo(
src: 'str',
present=True,
baseurl: 'str | None' = None,
description: 'str | None' = None,
enabled=True,
gpgcheck=True,
gpgkey: 'str | None' = None,
**kwargs,
)
- src: URL or name for the
.repofile - present: whether the
.repofile should be present - baseurl: the baseurl of the repo (if
srcis not a URL) - 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 src 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.repo(
name="Install Docker-CE repo via URL",
src="https://download.docker.com/linux/centos/docker-ce.repo",
)
# Create the repository file from baseurl/etc
yum.repo(
name="Add the Docker repo",
src="DockerCE",
baseurl="https://download.docker.com/linux/centos/7/$basearch/stable",
)
Global arguments
This operation also inherits all global arguments.
yum.rpm¶
Add/remove .rpm file packages.
- src: filename or URL of the
.rpmpackage - 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:
major_version = host.get_fact(LinuxDistribution)["major"]
dnf.rpm(
name="Install EPEL rpm to enable EPEL repo",
src=f"https://dl.fedoraproject.org/pub/epel/epel-release-latest-{major_version}.noarch.rpm",
)
Global arguments
This operation also inherits all global arguments.
yum.update¶
Stateless operation
This operation will always execute commands and is not idempotent.
Updates all yum packages.
Global arguments
This operation also inherits all global arguments.