What are Operations?
Operations are Python functions that:- Define the desired state of system resources
- Generate commands to achieve that state
- Are idempotent (can be run multiple times safely)
- Return information about changes made
Package Manager Operations
Pyinfra supports a wide range of package managers across different operating systems:Linux Package Managers
apt
Debian/Ubuntu package management with apt-get
yum
RHEL/CentOS package management with yum
dnf
Fedora/RHEL 8+ package management with dnf
apk
Alpine Linux package management
pacman
Arch Linux package management
zypper
openSUSE package management
BSD Package Managers
pkg
FreeBSD/OpenBSD/NetBSD package management
macOS Package Managers
brew
Homebrew package management for macOS
Windows Package Managers
choco
Chocolatey package management for Windows
Language-Specific Package Managers
pip
Python package management with pip
pipx
Python application management with pipx
npm
Node.js package management with npm
gem
Ruby gem package management
cargo
Rust package management with cargo
Common Patterns
Installing Packages
Version Pinning
Most package managers support version pinning:Ensuring Latest Versions
Operation Arguments
Most operations share common arguments:name: Description of what the operation does (optional but recommended)packages: List of packages to managepresent: Whether packages should be installed (default:True)latest: Whether to upgrade to latest versionupdate: Run package index update before installing
Best Practices
Always use descriptive names
Always use descriptive names
Update package indexes when needed
Update package indexes when needed
Pin versions for reproducibility
Pin versions for reproducibility
Next Steps
System Operations
Learn about file, directory, and system operations
Service Management
Manage systemd and other init systems
