Getting Started

This guide should help describe the basics of deploying stuff with pyinfra.


pyinfra requires Python and can be installed with pip:

$ pip install pyinfra
$ pyinfra (on Windows: python -m pyinfra)

    pyinfra -i INVENTORY DEPLOY [-vv options]
    pyinfra -i INVENTORY --run OP ARGS [-vv options]
    pyinfra -i INVENTORY --run COMMAND [-vv options]
    pyinfra -i INVENTORY --fact FACT [-vv options]

Command Line Ops

To deploy something with pyinfra, you need an inventory and some operations:

  • The inventory holds the target hosts, groups and any data associated with them
  • The operations define the desired state of the target hosts, and are grouped as modules

Lets start by running a deploy that will ensure user “fred” exists, using the server.user operation:

pyinfra -i --run server.user fred --sudo  # --user, --key

The --sudo flag used to run the operation with sudo. To connect & authenticate with the remote host you can use the --port, --user, --key and password --password flags.

The Deploy File

To write persistent (on disk) deploys with pyinfra you just use a Python file, eg. In this file you import the pyinfra modules needed and define the remote state desired with function calls:

# Import pyinfra modules, each containing operations to use
from pyinfra.modules import server

# Ensure the state of a user

Like above, this deploy ensures user “vivian” exists, using the server module. To execute the deploy:

pyinfra -i

That’s the basics of pyinfra! There’s a lot of other features like facts, groups, data which are described in the building a deploy guide. Also see the modules index and the example deploy on GitHub.