from pyinfra import host, local if 'misc_servers' in host.groups: local.include('apt.py') local.include('npm.py') local.include('files.py') local.include('server.py') local.include('virtualbox/virtualbox.py') if 'docker_servers' in host.groups: local.include('docker_ce.py')
from pyinfra import local # dependencies local.include("tasks/packages/git.py") local.include("tasks/packages/trizen.py") # shell local.include("tasks/packages/zsh.py") local.include("tasks/packages/pywal.py") local.include("tasks/packages/nvim.py") local.include("tasks/packages/ranger.py") local.include("tasks/packages/ripgrep.py")
from pyinfra import host, local local.include("tasks/setup_holepunch.py") local.include("tasks/setup_consul_template.py") local.include("tasks/setup_consul.py")
from pyinfra import host, local local.include("tasks/setup_holepunch.py") # local.include("tasks/setup_docker_v6.py") local.include("tasks/setup_consul_template.py") local.include("tasks/setup_vault_agent.py") local.include("tasks/setup_nomad.py")
from os import path from pyinfra import local, state from pyinfra.operations import server server.shell( name="First task operation", commands="echo first_task_operation", ) with state.preserve_loop_order([1, 2]) as loop_items: for item in loop_items(): server.shell( name="Task order loop {0}".format(item), commands="echo loop_{0}".format(item), ) server.shell( name="2nd Task order loop {0}".format(item), commands="echo loop_{0}".format(item), ) # Import a file *relative* to this one (./empty_task.py) local.include(path.join(".", "nested", "empty_task.py")) # Import a file from the CWD (tasks/another_task.py) local.include(path.join("tasks", "another_task.py"))
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', []), ) # Work with facts about the remote host # Storing this fact to avoid typing it so much (because the example targets a whole bunch # of distros [& 2 OSs]). distro = host.fact.linux_distribution # apt package manager apt.packages( ['git', 'python-pip'], sudo=True, update=True, cache_time=3600, # Limit operations to certain hosts with when=... when=distro['name'] in ('Ubuntu', 'Debian'),
from pyinfra import local # dependencies local.include("tasks/packages/git.py") local.include("tasks/packages/trizen.py") # shell local.include("tasks/packages/nvim.py") local.include("tasks/packages/pywal.py") local.include("tasks/packages/ranger.py") local.include("tasks/packages/ripgrep.py") local.include("tasks/packages/zsh.py") # desktop environment local.include("tasks/packages/bspwm.py") local.include("tasks/packages/dunst.py") local.include("tasks/packages/feh.py") local.include("tasks/packages/fonts.py") local.include("tasks/packages/gtk.py") local.include("tasks/packages/pipewire.py") local.include("tasks/packages/polybar.py") local.include("tasks/packages/redshift.py") local.include("tasks/packages/rofi.py") local.include("tasks/packages/sxhkd.py") local.include("tasks/packages/synaptics.py") local.include("tasks/packages/xorg.py") # user applications local.include("tasks/packages/ahoviewer.py") local.include("tasks/packages/alacritty.py") local.include("tasks/packages/fcitx.py")
from pyinfra import local local.include("tasks/add_ssh_admins.py") local.include("tasks/setup_holepunch.py") local.include("tasks/setup_docker_v6.py") local.include("tasks/setup_consul_template.py") local.include("tasks/setup_vault_agent.py") local.include("tasks/setup_nomad_consul.py") local.include("tasks/setup_nomad.py")
import os from subprocess import check_call from pyinfra import host, local from pyinfra.operations import apt, files, init, postgresql, server os.chdir(os.path.dirname('./' + __file__)) cwd = os.path.abspath('.') project_root = os.path.abspath('../..') local.include('base.py') files.sync( name='Sync templates', src=project_root + '/contrib/templates', dest='/var/lib/hockeypuck/templates', user='******', group='root', mode='644', delete=True, sudo=True, ) files.sync( name='Sync webroot', src=project_root + '/contrib/webroot', dest='/var/lib/hockeypuck/www', user='******', group='root', mode='644', delete=True,
from pyinfra import host, local, state from pyinfra.modules import files, server server.shell( {'First main operation'}, 'echo first_main_op', ) # Create some conditional branches if host.name == 'somehost': server.shell( {'Second main operation'}, 'echo second_main_op', ) 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',
from pyinfra import host, local if "misc_servers" in host.groups: local.include("apt.py") local.include("npm.py") local.include("files.py") local.include("server.py") local.include("virtualbox/virtualbox.py") if "docker_servers" in host.groups: local.include("docker_ce.py")
# 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.d('crond', running=True, sudo=True, ignore_errors=True) # Include roles local.include( 'roles/bsd_role.py', hosts=inventory.bsd # optionally limit the role to a subset of hosts ) # Storing this fact to avoid typing it so much (because the example targets a whole bunch # of distros [& 2 OSs]). distro = host.fact.linux_distribution # Work with facts about the remote host if distro['name'] in ('Debian', 'Ubuntu'): # apt package manager apt.packages(['git', 'python-pip'], sudo=True, update=True, cache_time=3600) elif distro['name'] in ('CentOS', 'Fedora'):
]) # 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 roles local.include( 'roles/bsd_role.py', hosts=inventory.get_group('bsd'), ) # Storing this fact to avoid typing it so much (because the example targets a whole bunch # of distros [& 2 OSs]). distro = host.fact.linux_distribution # Work with facts about the remote host if distro['name'] in ('Debian', 'Ubuntu'): # apt package manager apt.packages( ['git', 'python-pip'], sudo=True, update=True, cache_time=3600, )
) server.shell( name="First main operation", commands="echo first_main_op", ) # Create some conditional branches if host.name == "somehost": server.shell( name="Second main operation", commands="echo second_main_op", ) elif host.name == "anotherhost": local.include(path.join("tasks", "a_task.py")) # Include the whole file again, but for all hosts local.include(path.join("tasks", "a_task.py")) # Execute the @deploy function my_deploy() # Do a loop which will generate duplicate op hashes for i in range(2): server.shell( name="Loop-{0} main operation".format(i), commands="echo loop_{0}_main_operation".format(i), ) call_file_op()
from pyinfra import local # shell local.include("tasks/configs/git.py") local.include("tasks/configs/zsh.py") local.include("tasks/configs/pywal.py") local.include("tasks/configs/nvim.py") local.include("tasks/configs/ranger.py")
from os import path from pyinfra import local, state from pyinfra.operations import server server.shell( name='First task operation', commands='echo first_task_operation', ) with state.preserve_loop_order([1, 2]) as loop_items: for item in loop_items(): server.shell( name='Task order loop {0}'.format(item), commands='echo loop_{0}'.format(item), ) server.shell( name='2nd Task order loop {0}'.format(item), commands='echo loop_{0}'.format(item), ) # Import a file *relative* to this one (./another_task.py) local.include(path.join('.', 'another_task.py'))
from pyinfra import local # shell local.include("tasks/configs/git.py") local.include("tasks/configs/zsh.py") local.include("tasks/configs/pywal.py") local.include("tasks/configs/nvim.py") local.include("tasks/configs/ranger.py") # desktop environment local.include("tasks/configs/bspwm.py") local.include("tasks/configs/dunst.py") local.include("tasks/configs/feh.py") local.include("tasks/configs/gtk.py") local.include("tasks/configs/polybar.py") local.include("tasks/configs/redshift.py") local.include("tasks/configs/rofi.py") local.include("tasks/configs/sxhkd.py") local.include("tasks/configs/xorg.py") # user applications local.include("tasks/configs/alacritty.py") local.include("tasks/configs/fcitx.py") local.include("tasks/configs/mpd.py") local.include("tasks/configs/mpv.py") local.include("tasks/configs/yt-dlp.py") # TODO # local.include("tasks/configs/firefox.py") # local.include("tasks/configs/qbittorrent.py") # local.include("tasks/configs/thunderbird.py")
from pyinfra.modules import server server.shell( {'First main operation'}, 'echo first_main_op', ) # Create some conditional branches if host.name == 'somehost': server.shell( {'Second main operation'}, 'echo second_main_op', ) elif host.name == 'anotherhost': local.include('a_task.py') # Include the whole file again, but for all hosts local.include('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), ) server.shell( {'Third main operation'}, 'echo third_main_op', )
# pyinfra # File: pyinfra/example/deploy.py # Desc: example deploy script for the pyinfra CLI # targets: Ubuntu/Debian, CentOS/Fedora & OpenBSD from pyinfra import host, local # These work everywhere local.include('basics.py') local.include('packages.py') local.include('callbacks.py') local.include('python_app.py') # Only suitable for Debian systems if 'debian' in host.groups: local.include('mysql.py') # And only for Debian if 'ubuntu' in host.groups: local.include('postgresql.py')