Skip to main content

Required Arguments

INVENTORY
string
required
Defines the target hosts. Can be:
  • A Python inventory file (e.g., inventory.py)
  • A single hostname (e.g., host.example.com)
  • Comma-separated hostnames (e.g., host1.com,host2.com,@local)
OPERATIONS
string
required
Specifies what to execute. Can be:
  • One or more deploy files (e.g., deploy.py)
  • An operation call (e.g., server.user pyinfra)
  • An exec command (e.g., exec -- echo hello)
  • A fact query (e.g., fact server.LinuxName)
  • Debug command (debug-inventory)

Output & Verbosity

-v
flag
Increase verbosity. Can be repeated up to 3 times:
  • -v: Print meta information and noop operations
  • -vv: Print input (commands sent to hosts)
  • -vvv: Print output (command results from hosts)
Example:
pyinfra inventory.py deploy.py -vvv
--dry
flag
Don’t execute operations on target hosts. Shows what would be changed without making actual changes.Example:
pyinfra inventory.py deploy.py --dry
--diff
flag
Show differences when changing text files and templates. Useful for reviewing file changes before applying.Example:
pyinfra inventory.py deploy.py --diff

Execution Control

-y, --yes
flag
Execute operations immediately without prompts or change detection. Can also be set via PYINFRA_YES environment variable.Example:
pyinfra inventory.py deploy.py -y
export PYINFRA_YES=1
pyinfra inventory.py deploy.py
--limit
string
Restrict target hosts by name or group name. Supports wildcards. Can be specified multiple times.Examples:
pyinfra inventory.py deploy.py --limit webservers
pyinfra inventory.py deploy.py --limit "web-*"
pyinfra inventory.py deploy.py --limit group1 --limit group2
--fail-percent
integer
Percentage of hosts that need to fail before exiting early. Default behavior prompts on any failure when not using -y.Example:
pyinfra inventory.py deploy.py --fail-percent 25
--parallel
integer
Number of operations to run in parallel. Controls concurrent execution across hosts.Example:
pyinfra inventory.py deploy.py --parallel 10
--serial
flag
Run operations in serial, host by host, instead of operation by operation.Example:
pyinfra inventory.py deploy.py --serial
--no-wait
flag
Don’t wait between operations for hosts. Executes operations immediately without delays.Example:
pyinfra inventory.py deploy.py --no-wait
--retry
integer
default:"0"
Number of times to retry failed operations.Example:
pyinfra inventory.py deploy.py --retry 3
--retry-delay
integer
default:"5"
Delay in seconds between retry attempts.Example:
pyinfra inventory.py deploy.py --retry 3 --retry-delay 10

Data & Configuration

--data
string
Override data values in format key=value. Can be specified multiple times. Values are automatically parsed (booleans, numbers, strings).Examples:
pyinfra inventory.py deploy.py --data env=production
pyinfra inventory.py deploy.py --data debug=true --data workers=4
--group-data
string
Paths to load additional group data from. Overrides matching keys. Can be specified multiple times.Example:
pyinfra inventory.py deploy.py --group-data ./extra-data/
--config
string
default:"config.py"
Specify config file to use instead of default config.py.Example:
pyinfra inventory.py deploy.py --config production-config.py
--chdir
string
Set the working directory before executing. All relative paths will be resolved from this directory.Example:
pyinfra inventory.py deploy.py --chdir /path/to/project

Authentication & Privilege

--sudo
flag
Execute operations with sudo (as root or another user).Example:
pyinfra inventory.py deploy.py --sudo
--sudo-user
string
Which user to sudo to when using --sudo.Example:
pyinfra inventory.py deploy.py --sudo --sudo-user postgres
--use-sudo-password
flag
Use a password with sudo. pyinfra will prompt for the password.Example:
pyinfra inventory.py deploy.py --sudo --use-sudo-password
--same-sudo-password
flag
All hosts have the same sudo password, so ask only once instead of per-host.Example:
pyinfra inventory.py deploy.py --sudo --same-sudo-password
--su-user
string
Which user to su to for privilege escalation (alternative to sudo).Example:
pyinfra inventory.py deploy.py --su-user root
--shell-executable
string
Shell to use for command execution. Examples: sh, bash, cmd, ps (PowerShell).Examples:
pyinfra inventory.py deploy.py --shell-executable sh
pyinfra windows-hosts deploy.py --shell-executable ps

SSH Connection

--ssh-user, --user
string
SSH user to connect as.Example:
pyinfra inventory.py deploy.py --ssh-user ubuntu
--ssh-port, --port
integer
SSH port to connect to.Example:
pyinfra inventory.py deploy.py --ssh-port 2222
--ssh-key, --key
path
SSH private key filename for authentication.Example:
pyinfra inventory.py deploy.py --ssh-key ~/.ssh/id_rsa_deploy
--ssh-key-password, --key-password
string
SSH private key password if the key is encrypted.Example:
pyinfra inventory.py deploy.py --ssh-key ~/.ssh/id_rsa --ssh-key-password
--ssh-password, --password
string
SSH password for authentication (less secure than key-based auth).Example:
pyinfra inventory.py deploy.py --ssh-password
The non-prefixed variants (--user, --port, --key, etc.) are deprecated and may be removed in future versions. Use the --ssh-* prefixed versions instead.

Debug & Development

--debug
flag
Print debug logs from pyinfra. Shows detailed internal operations.Example:
pyinfra inventory.py deploy.py --debug
--debug-all
flag
Print debug logs from all packages including pyinfra. Very verbose output.Example:
pyinfra inventory.py deploy.py --debug-all
--debug-facts
flag
Print facts after generating operations and exit without executing. Useful for debugging fact collection.Example:
pyinfra inventory.py deploy.py --debug-facts
--debug-operations
flag
Print operations after generating and exit without executing. Shows the operation plan.Example:
pyinfra inventory.py deploy.py --debug-operations

Information & Help

-h, --help
flag
Show help message and exit.Example:
pyinfra --help
--version
flag
Show pyinfra version and exit.Example:
pyinfra --version
--support
flag
Print useful information for support (version, Python version, platform) and exit.Example:
pyinfra --support

Common Combinations

Dry Run with Verbose Output

pyinfra inventory.py deploy.py --dry -vv
See what would be executed with detailed input information.

Production Deployment

pyinfra inventory.py deploy.py \
  --limit production \
  --data env=production \
  --sudo \
  -y
Execute immediately on production hosts with sudo.

Debug Deployment

pyinfra inventory.py deploy.py \
  --debug \
  --dry \
  -vvv
Full debug output with dry run.

Serial Execution with Retries

pyinfra inventory.py deploy.py \
  --serial \
  --retry 3 \
  --retry-delay 10
Run host-by-host with retries on failure.

Custom SSH Configuration

pyinfra inventory.py deploy.py \
  --ssh-user deploy \
  --ssh-port 2222 \
  --ssh-key ~/.ssh/deploy_key \
  --sudo
Connect with specific SSH settings and use sudo.

Build docs developers (and LLMs) love