Skip to content

zypper Operations

Facts used in these operations: rpm.RpmPackages.

zypper.packages

Install/remove/update zypper packages & updates.

zypper.packages(
         packages: 'str | list[str] | None' = None,
         present=True,
         latest=False,
         update=False,
         clean=False,
         extra_global_install_args: 'str | None' = None,
         extra_install_args: 'str | None' = None,
         extra_global_uninstall_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 zypper update before installing packages
  • clean: run zypper clean --all before installing packages
  • extra_global_install_args: additional global arguments to the zypper install command
  • extra_install_args: additional arguments to the zypper install command
  • extra_global_uninstall_args: additional global arguments to the zypper uninstall command
  • extra_uninstall_args: additional arguments to the zypper uninstall command

Versions: Package versions can be pinned like zypper: <pkg>=<version>

Examples:

# Update package list and install packages
zypper.packages(
    name="Install Vim and Vim enhanced",
    packages=["vim-enhanced", "vim"],
    update=True,
)

# Install the latest versions of packages (always check)
zypper.packages(
    name="Install latest Vim",
    packages=["vim"],
    latest=True,
)

Global arguments

This operation also inherits all global arguments.

zypper.repo

Add/remove/update zypper repositories.

zypper.repo(
         src,
         baseurl=None,
         present=True,
         description=None,
         enabled=True,
         gpgcheck=True,
         gpgkey=None,
         type='rpm-md',
         **kwargs,
    )
  • src: 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
  • type: the type field this repo (defaults to rpm-md)

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:

from pyinfra.operations import zypper
# Download a repository file
zypper.repo(
    name="Install container virtualization repo via URL",
    src="https://download.opensuse.org/repositories/Virtualization:containers/openSUSE_Tumbleweed/Virtualization:containers.repo",
)

# Create the repository file from baseurl/etc
zypper.repo(
    name="Install container virtualization repo",
    src=="Virtualization:containers (openSUSE_Tumbleweed)",
    baseurl="https://download.opensuse.org/repositories/Virtualization:/containers/openSUSE_Tumbleweed/",
)

Global arguments

This operation also inherits all global arguments.

zypper.rpm

Add/remove .rpm file packages.

zypper.rpm(src, present=True,
         **kwargs,
    )
  • src: 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:

zypper.rpm(
   name="Install task from rpm",
   src="https://github.com/go-task/task/releases/download/v2.8.1/task_linux_amd64.rpm",
)

Global arguments

This operation also inherits all global arguments.

zypper.update

Stateless operation

This operation will always execute commands and is not idempotent.

Updates all zypper packages.

zypper.update**kwargs,    )

Global arguments

This operation also inherits all global arguments.