) # Generate files from local jinja2 templates files.template( 'templates/template.txt.j2', '/home/vagrant/template.txt', ) # Execute arbitrary shell commands server.shell([ 'echo "Shell command"', 'echo "My hostname is {{ host.fact.hostname }}"', ]) # and scripts server.script( 'files/test.sh', ) # Manage init systems init.service( 'cron', running=True, sudo=True, ignore_errors=True, on_error=on_pyinfra_error, ) # Include other files local.include( 'tasks/bsd_python.py', hosts=inventory.get_group('bsd', []),
from pyinfra.modules import server SUDO = True # Various different outputs # To see output need to run pyinfra with '-v' a = server.script( {'Hello'}, 'files/hello.bash', ) print('a', a) # To see output need to run pyinfra with '-v' b = server.shell( {'Say Hello'}, 'echo Hello', ) print('b', b)
from pyinfra import host from pyinfra.modules import server SUDO = True ip = host.fact.ipv4_addresses['eth0'] if ip.startswith('10.'): server.script( {'Remove 10. network from eth0'}, 'files/remove_10_on_eth0.bash', )
files.template( {'Generate/upload templates/template.txt.j2'}, 'templates/template.txt.j2', '/home/vagrant/template.txt', ) server.shell( {'Execute some shell commands'}, [ 'echo "Shell command"', 'echo "My hostname is {{ host.fact.hostname }}"', ], ) # and scripts server.script( {'Run the files/test.sh script'}, 'files/test.sh', ) # Copy local files to remote host files.put( {'Upload files/file.txt'}, 'files/file.txt', '/home/vagrant/file.txt', mode=777, ) # and sync directories files.sync( {'Sync the files directory'}, 'files', '/home/vagrant/example_files', delete=True,