LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

pyinfra

Automate infrastructure deployment with Python

TLDR

Deploy to servers
$ pyinfra [inventory] [deploy.py]
copy
Run command on servers
$ pyinfra [inventory] exec -- [command]
copy
Check what would change
$ pyinfra --dry [inventory] [deploy.py]
copy
Deploy with facts
$ pyinfra [inventory] fact [server.Hostname]
copy

SYNOPSIS

pyinfra [options] inventory operations

DESCRIPTION

pyinfra automates infrastructure provisioning and configuration management using Python. Deploy scripts are written as regular Python files that describe desired system state through operations like installing packages, managing files, configuring services, and executing commands across groups of servers.The tool connects to targets over SSH without requiring agents on remote machines, making it lightweight to adopt. An inventory file defines target hosts and groups, while deploy scripts specify what operations to run. The --dry flag previews changes before applying them, and the fact command gathers system information from targets for conditional logic in deployments.

PARAMETERS

INVENTORY

Target hosts file.
OPERATIONS
Deploy script or commands.
--dry
Dry run mode; print operations without executing.
--limit HOSTS
Filter execution to specific hosts by name or glob pattern.
--retry N
Retry failed operations up to N times.
--debug-inventory
Print inventory hosts, groups, and data.
--debug-facts
Show facts after generating operations and exit.
--debug-operations
Show operations after generating and exit.
exec
Execute an arbitrary shell command on hosts.
fact
Gather facts from target hosts.
-v, -vv, -vvv
Increase verbosity (facts, shell input, shell output).

CONFIGURATION

inventory.py

Default inventory file defining target hosts, groups, and connection details for deployments.
deploy.py
Default deploy script containing operations to execute on target hosts.
**group_data/*.py**
Group-specific data files providing variables for host groups defined in the inventory.
config.py
Project-level configuration for SSH settings, sudo behavior, and operation defaults.

CAVEATS

Python required. SSH-based deployment.

HISTORY

pyinfra was created for Python-based infrastructure automation.

SEE ALSO

ansible(1), fabric(1), salt(1)

Copied to clipboard
Kai