Skip to main content
The zypper module manages packages and repositories on openSUSE and SUSE Linux Enterprise systems.

Functions

packages

Install, remove, or update zypper packages.
from pyinfra.operations import zypper

zypper.packages(
    name="Install development tools",
    packages=["git", "vim"],
    update=True,
)
packages
str | list[str]
List of packages to ensure.
present
bool
default:true
Whether the packages should be installed.
latest
bool
default:false
Whether to upgrade packages without a specified version.
update
bool
default:false
Run zypper update before installing packages.
clean
bool
default:false
Run zypper clean --all before installing packages.
extra_global_install_args
str
Additional global arguments to the zypper install command.
extra_install_args
str
Additional arguments to the zypper install command.
extra_global_uninstall_args
str
Additional global arguments to the zypper uninstall command.
extra_uninstall_args
str
Additional arguments to the zypper uninstall command.
Package versions can be pinned like zypper: <pkg>=<version>

Examples

from pyinfra.operations import zypper

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

update

Update all zypper packages.
from pyinfra.operations import zypper

zypper.update(
    name="Update all packages",
)
This operation is not idempotent - it will always execute.

repo

Add, remove, or update zypper repositories.
from pyinfra.operations import zypper

zypper.repo(
    name="Add container virtualization repo",
    src="Virtualization:containers",
    baseurl="https://download.opensuse.org/repositories/Virtualization:/containers/openSUSE_Tumbleweed/",
)
src
str
required
URL or name for the .repo file.
baseurl
str
The baseurl of the repo (if src is not a URL).
present
bool
default:true
Whether the .repo file should be present.
description
str
Optional verbose description.
enabled
bool
default:true
Whether this repo is enabled.
gpgcheck
bool
default:true
Whether to set gpgcheck=1.
gpgkey
str
The URL to the GPG key for this repo.
type
str
default:"rpm-md"
The type field for this repo.
baseurl, description, gpgcheck, and gpgkey are only valid when src is a filename (not a URL). 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",
)

rpm

Install or remove .rpm package files.
from pyinfra.operations import zypper

zypper.rpm(
    name="Install task from rpm",
    src="https://github.com/go-task/task/releases/download/v2.8.1/task_linux_amd64.rpm",
)
src
str
required
Filename or URL of the .rpm package.
present
bool
default:true
Whether 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.

key

Add zypper GPG keys with rpm.
from pyinfra import host
from pyinfra.operations import zypper
from pyinfra.facts.server import LinuxDistribution

linux_id = host.get_fact(LinuxDistribution)["release_meta"].get("ID")
zypper.key(
    name="Add Docker GPG key",
    src=f"https://download.docker.com/linux/{linux_id}/gpg",
)
src
str
required
Filename or URL of the GPG key.
This operation is not idempotent - it always returns one command without state checking.
The key operation is inherited from the yum module.

Common Use Cases

Install Docker on openSUSE

from pyinfra.operations import zypper

# Add Docker repository
zypper.repo(
    name="Add Docker repository",
    src="https://download.docker.com/linux/sles/docker-ce.repo",
)

# Install Docker
zypper.packages(
    name="Install Docker",
    packages=["docker-ce", "docker-ce-cli", "containerd.io"],
)

Development Environment

from pyinfra.operations import zypper

# Install development patterns
zypper.packages(
    name="Install development pattern",
    packages=["devel_basis"],
)

# Install additional tools
zypper.packages(
    name="Install development tools",
    packages=[
        "git",
        "vim",
        "tmux",
        "wget",
        "curl",
    ],
    update=True,
)

Web Server Setup

from pyinfra.operations import zypper

zypper.packages(
    name="Install web server stack",
    packages=[
        "nginx",
        "php",
        "php-fpm",
        "mariadb",
    ],
    update=True,
)

System Update

from pyinfra.operations import zypper

# Clean metadata
zypper.packages(
    name="Clean zypper cache",
    packages=[],
    clean=True,
)

# Update all packages
zypper.update(
    name="Update all packages",
)

Install from Custom Repository

from pyinfra.operations import zypper

# Add custom repository
zypper.repo(
    name="Add Packman repository",
    src="packman",
    baseurl="https://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_Tumbleweed/",
    type="rpm-md",
)

# Install packages from repository
zypper.packages(
    name="Install multimedia codecs",
    packages=["ffmpeg", "vlc"],
)

openSUSE-Specific Tips

openSUSE uses patterns for installing groups of related packages:
from pyinfra.operations import zypper

# Install development pattern
zypper.packages(
    name="Install development pattern",
    packages=["devel_basis", "devel_C_C++"],
)
List and manage repositories:
from pyinfra.operations import server

# List repositories
server.shell(
    name="List repositories",
    commands=["zypper repos"],
)

# Refresh repositories
server.shell(
    name="Refresh repositories",
    commands=["zypper refresh"],
)
Lock packages to prevent updates:
from pyinfra.operations import server

# Lock a package
server.shell(
    name="Lock kernel package",
    commands=["zypper addlock kernel-default"],
)

# Unlock a package
server.shell(
    name="Unlock kernel package",
    commands=["zypper removelock kernel-default"],
)
Upgrade to a new openSUSE version:
from pyinfra.operations import server

# Distribution upgrade
server.shell(
    name="Upgrade distribution",
    commands=["zypper dup --no-confirm"],
)

Important Notes

Zypper automatically uses the --non-interactive flag for all operations in pyinfra.
When using custom repositories, always verify the repository’s authenticity and import the GPG key before installing packages.

Build docs developers (and LLMs) love