pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
server.service
operationfiles.*
factsTMPDIR
when asking for sudo password (@jaysoffian)python.*
operationsAdded:
selinux.boolean
, selinux.file_context
, selinux.file_context_mapping
& selinux.port
operations (@morrison12)selinux.SEBoolean
, selinux.FileContextMapping
, selinux.SEPorts
, selinux.SEPort
facts (@morrison12)snap.package
operation & snap.SnapPackage
, snap.SnapPackages
facts (@pabloxio)files.block
operation implementation (@morrison12)Fixed:
systemd.SystemdStatus
fact (@mariusmuja)rpm.RpmPackage
fact (@mariusmuja)host.loop
methodserver.Date
fact, should resolve any outstanding parse errorsOther changes:
macos-latest
GitHub runner (@morrison12)Delayed getting this out, lots of little improvements.
Added:
server.user_authorized_keys
operation_continue_on_error
argumentdir_mode
argument to files.sync
operation (@filips123)mode=True
in files.put
operationheaders
and insecure
arguments to files.download
operationFixed:
lxd.container
operation (@zachwaite)files.put
operationOther changes:
git.bare_repo
operationpathlib
objectsRelatively small quick release with two additions and a bunch of fixes.
Added:
create_home
argument to server.user
operationstdin
Fixed:
assume_exists=True
in files.put
operationInternal:
The main feature of 2.2
is the switch to using a DAG to generate operation order. This mostly replaces line-number ordering (still used to tie-break) and means hacks such as state.preserve_loop_order
are no longer required!
The second highlight feature is the inclusion of type stub files for operations that include all of the global arguments. Thank you to @StefanBRas for implementing this.
Other changes:
server.user
operation (@yunzheng)replace
as a whole line in files.line
operationmysql.privileges
invalid argument requesting MysqlUserGrants
factFirst 2.x
point release! Major feature: nested operations (at last!).
Based on the changes to operations in 2.x
nested operations make it possible to generate & execute operations on the fly at execution time, rather than using the low-level connector API. This unlocks all kinds of complex deploys that were previously impossible or complex to implement. Let's look at an example:
from pyinfra import logger
from pyinfra.operations import python, server
def callback():
result = server.shell(commands=["echo output"])
logger.info(f"Got result: {result.stdout}")
python.call(
name="Execute callback function",
function=callback,
)
Other new stuff:
host.reload_fact(...)
- bypasses the fact cache to force reloading of fact datadeb.DebArch
factssh_paramiko_connect_kwargs
host data used in the @ssh
connectorBugfixes:
files.put
hashing local file that doesn't exist when assume_exists=True
zypper
over apt
when both present in server.packages
operationInternal changes:
black
and isort
across the codebase, now part of CIconfig.SUDO
/etc handling for operation argument defaultssystemd
facts using systemctl show
files.template
operationaccept-new
SSH config for StrictHostKeyChecking
config.REQUIRE_PYINFRA_VERSION
& config.REQUIRE_PACKAGES
handlingpyinfra automates/provisions/manages/deploys infrastructure. It can be used for ad-hoc command execution, service deployment, configuration management and more. See the readme for more information.
The first 2.x
release! Like v0 -> v1 this release mostly removes legacy APIs and methods which show warnings in v1. Major changes:
Breaking: Python 2.7 (finally!), 3.5 support dropped, Python 3.6 is now the minimum required version.
Breaking: the "deploy directory" concept has been removed - everything now executes from the current working directory which removes the ambiguous magic v1 used to pick a deploy directory. A new --chdir
CLI flag has been added to set the working directory before pyinfra
executes.
This may affect scripts or CI workflows currently setup, for example:
# Old v1, deploy directory becomes deploys/elasticsearch/
pyinfra deploys/elasticsearch/inventories/production.py deploys/elasticsearch/deploy.py
# New v2, explicit chdir required
pyinfra --chdir deploys/elasticsearch/ inventories/production.py deploy.py
Parallel operation generation & facts rewrite - this is a huge improvement to how pyinfra
generates commands to run on target hosts. This is now run in parallel across all hosts. Facts are now collected by individual host rather than across all hosts which may yield significant speedups in certain situations.
This change also brings support for all of the execution global arguments to facts, and hugely simplifies the facts implementation. Global arguments will now be read from host data in exactly the same way they are for operations, which was often a confusing gotcha in v1. This also means that the arguments can have different values for each host and this will not cause issues.
Other breaking changes (warnings shown in v1 for most):
AttributeError
when accessed via host.data.X
branch
argument to None
in git.repo
operationpresent
argument removed from mysql.privileges
operationconfig
objecthost.fact.fact_name
access has been removedinit.*
operations have been removed--facts
and --operations
CLI flags--debug-data
CLI flagWindows
prefix on all Windows factsname
argument to path
in windows_files.*
operationspyinfra.modules
module/importconfig.MIN_PYINFRA_VERSION
branch
and create_branch
arguments in git.worktree
operationtouch_periodic
argument in apt.update
operation (never used)pyinfra.api.connectors
module moved to pyinfra.connectors
Deprecated (showing warnings, to be removed in v3):
state
and host
arguments no longer need to be passed into operation or deploy functionspostgresql_*
arguments renamed to psql_*
in postgresql.*
operations & facts