Global Arguments¶
In addition to each operations having its own arguments, there are a number of keyword arguments available in all facts, operations and deploys.
Note
With the exception of name
these are prefixed with _
to avoid clashes with other operation and deploy arguments.
Privilege & user escalation¶
Caution
When combining privilege escalation arguments it is important to know the order they
are applied: doas
-> sudo
-> su
. For example
_sudo=True,_su_user="pyinfra"
yields a command like sudo su pyinfra..
.
Key |
Description |
Type |
Default |
---|---|---|---|
|
Execute/apply any changes with sudo. |
|
|
|
Execute/apply any changes with sudo as a non-root user. |
|
|
|
Execute sudo with a login shell. |
|
|
|
Password to sudo with. If needed and not specified pyinfra will prompt for it. |
|
|
|
Preserve the shell environment of the connecting user when using sudo. |
|
|
|
Execute/apply any changes with this user using su. |
|
|
|
Execute su with a login shell. |
|
|
|
Preserve the shell environment of the connecting user when using su. |
|
|
|
Use this shell (instead of user login shell) when using |
|
|
|
Execute/apply any changes with doas. |
|
|
|
Execute/apply any changes with doas as a non-root user. |
|
Examples:
# Execute a command with sudo
server.user(
name="Create pyinfra user using sudo",
user="pyinfra",
_sudo=True,
)
# Execute a command with a specific sudo password
server.user(
name="Create pyinfra user using sudo",
user="pyinfra",
_sudo=True,
_sudo_password="my-secret-password",
)
Shell control & features¶
Key |
Description |
Type |
Default |
---|---|---|---|
|
The shell executable to use for executing commands. |
|
|
|
Directory to switch to before executing the command. |
|
|
|
Dictionary of environment variables to set. |
|
|
|
List of exit codes to consider a success. |
|
|
|
Timeout for each command executed during the operation. |
|
|
|
Whether to get a pseudoTTY when executing any commands. |
|
|
|
String or buffer to send to the stdin of any commands. |
|
Examples:
# Execute from a specific directory
server.shell(
name="Bootstrap nginx params",
commands=["openssl dhparam -out dhparam.pem 4096"],
_chdir="/etc/ssl/certs",
)
Operation meta & callbacks¶
Key |
Description |
Type |
Default |
---|---|---|---|
|
Name of the operation. |
|
|
|
Ignore errors when executing the operation. |
|
|
|
Continue executing operation commands after error. Only applies when |
|
|
|
Only run this operation if these functions return True |
|
|
Execution strategy¶
Key |
Description |
Type |
Default |
---|---|---|---|
|
Run this operation in batches of hosts. |
|
|
|
Only execute this operation once, on the first host to see it. |
|
|
|
Run this operation host by host, rather than in parallel. |
|
|