Skip to content

⚡ Deploy stuff by diff-ing the state you want against the remote server

License

Notifications You must be signed in to change notification settings

mikeatm/pyinfra

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyinfra PyPI version

pyinfra automates service deployment. It does this by diffing the state of the server with the state defined in the deploy script. Deploys are asyncronous and highly performant. The inventory & deploy are managed with pure Python, allowing for near-infinite extendability.

When you run pyinfra -i INVENTORY DEPLOY, you'll see something like:

A inventory file might look like:

GROUP = [
    'my.hostname'
]

And a deploy file like:

# These modules contain operations, which provide ways to set desired state
# for the remove service.
from pyinfra.modules import files, server

# Ensure the state of a user
server.user(
    'pyinfra',
    present=True,
    home='/home/pyinfra'
)

# Ensure the state of files
files.file(
    '/var/log/pyinfra.log',
    user='pyinfra',
    group='pyinfra',
    permissions='644',
    sudo=True
)

Alternatively, you can use the Python API:

from pyinfra import state

from pyinfra.api import Inventory, State
from pyinfra.api.operation import add_op
from pyinfra.api.operations import run_ops
from pyinfra.api.ssh import connect_all
from pyinfra.api.facts import get_facts

from pyinfra.modules import files, server

# Setup inventory of target hosts
inventory = Inventory(
    ([
        'my.hostname'
    ], {}),
    ssh_user='user',
    ssh_key='/path/to/keyfile'
)

# Setup the pyinfra state for this deploy
state.new(State(inventory))

# Connect to all the hosts
connect_all()

# Now we can build up a list of operations to run (running facts as required)
add_op(
    server.user,
    'pyinfra',
    present=True,
    home='/home/pyinfra'
)

# Ensure the state of files
add_op(
    files.file,
    '/var/log/pyinfra.log',
    user='pyinfra',
    group='pyinfra',
    permissions='644',
    sudo=True
)

# And finally we run the ops
run_ops()

About

⚡ Deploy stuff by diff-ing the state you want against the remote server

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.1%
  • Other 1.9%