on_success=on_pyinfra_success, ) # And groups server.group( {'Ensure pyinfra2 group exists'}, # use a set as the first arg to set the op name 'pyinfra2', sudo=True, run_once=True, # run only on one host ) # Ensure the state of files files.file( '/var/log/pyinfra.log', user='******', group='pyinfra', mode=644, sudo=True, ) # Ensure the state of directories files.directory( host.data.env_dir, user='******', group='pyinfra', mode=755, recursive=True, sudo=True, serial=True, )
'/tmp/foo', foo_variable=foo_variable, ) files.link( {'Create link /etc/issue2 that points to /etc/issue'}, '/etc/issue2', '/etc/issue', ) # Note: The directory /tmp/secret will get created with the default umask. files.file( {'Create /tmp/secret/file'}, '/tmp/secret/file', mode='600', user='******', group='root', touch=True, create_remote_dir=True, ) files.directory( {'Ensure the /tmp/dir_that_we_want_removed is removed'}, '/tmp/dir_that_we_want_removed', present=False, ) # multiple directories dirs = ['/tmp/aaa', '/tmp/bbb'] for dir in dirs: files.directory(
elif host.name == 'anotherhost': local.include('tasks/a_task.py') # Include the whole file again, but for all hosts local.include('tasks/a_task.py') # Do a loop which will generate duplicate op hashes for i in range(2): server.shell( {'Loop-{0} main operation'.format(i)}, 'echo loop_{0}_main_operation'.format(i), ) files.file( {'Third main operation'}, 'files/a_file', '/a_file', ) with state.preserve_loop_order([1, 2]) as loop_items: for item in loop_items(): server.shell( {'Order loop {0}'.format(item)}, 'echo loop_{0}'.format(item), ) server.shell( {'2nd Order loop {0}'.format(item)}, 'echo loop_{0}'.format(item), ) if host.name == 'somehost':
from pyinfra.modules import files, server CONNECT_TIMEOUT = 1 FAIL_PERCENT = 0 server.user( {'Add pyinfra user'}, 'pyinfra', home='/home/pyinfra', shell='/bin/bash', ) files.file( {'Add log file'}, '/var/log/pyinfra.log', user='******', mode=777, ) files.put( {'Copy a file'}, '../files/test_file.txt', '/home/pyinfra/test_file.txt', user='******', ) server.shell( {'Run some shell'}, 'echo "hi!"', )
sudo=True, ) # And groups server.group( {'Ensure pyinfra2 group exists' }, # use a set as the first arg to set the op name 'pyinfra2', sudo=True, ) # Ensure the state of files files.file( {'Ensure pyinfra.log exists'}, '/var/log/pyinfra.log', user='******', group='pyinfra', mode=644, sudo=True, ) # Ensure the state of directories files.directory( {'Ensure {{ host.data.env_dir }} exists exists'}, host.data.env_dir, user='******', group='pyinfra', mode=755, sudo=True, )