from pyinfra import host, inventory from pyinfra.operations import init, puppet, server SUDO = True USE_SUDO_LOGIN = True if host in inventory.get_group('master_servers'): server.script_template( {'Sign the agent, if needed'}, 'templates/sign_agent.bash.j2', ) if host in inventory.get_group('agent_servers'): init.systemd( {'Temp stop puppet agent so we can ensure a good run'}, 'puppet', running=False, ) # Either 'USE_SUDO_LOGIN=True' or 'USE_SU_LOGIN=True' for # puppet.agent() as `puppet` is added to the path in # the .bash_profile. # We also expect a return code of: # 0=no changes or 2=changes applied puppet.agent( {'Run the puppet agent'}, success_exit_codes=[0, 2], )
SUDO = True # update the /etc/hosts file def update_hosts_file(name, ip): name = name.replace('@vagrant/', '') files.line( name='Add hosts to /etc/hosts', path='/etc/hosts', line=r' {}.example.com '.format(name), replace='{} {}.example.com {}'.format(ip, name, name), ) # ensure all hosts are added to each /etc/hosts file inv = inventory.get_group('@vagrant') for item in inv: update_hosts_file(item.name, item.fact.ipv4_addresses['eth0']) if host.name == '@vagrant/two': server.hostname( name='Set the hostname for two', hostname='two.example.com', ) if host.name == '@vagrant/one': server.hostname( name='Set the hostname for one', hostname='one.example.com', )
SUDO = True # update the /etc/hosts file def update_hosts_file(name, ip): files.line( {'Add hosts to /etc/hosts'}, '/etc/hosts', r' {}.example.com '.format(name), replace='{} {}.example.com {}'.format(ip, name, name), ) # ensure all hosts are added to each /etc/hosts file masters = inventory.get_group('master_servers') for item in masters: update_hosts_file('master', item.fact.ipv4_addresses['eth0']) agents = inventory.get_group('agent_servers') for item in agents: update_hosts_file('agent', item.fact.ipv4_addresses['eth0']) if host in masters: server.hostname( {'Set the hostname for the Puppet Master'}, 'master.example.com', ) if host in agents: server.hostname( {'Set the hostname for an agent'},
from pyinfra import config, host, inventory from pyinfra.operations import files, puppet config.SUDO = True config.USE_SUDO_LOGIN = True if host in inventory.get_group("master_servers"): files.template( name="Create a puppet manifest", src="templates/environments/production/manifests/httpd.pp.j2", dest="/etc/puppetlabs/code/environments/production/manifests/httpd.pp", ) if host in inventory.get_group("agent_servers"): # Either 'USE_SUDO_LOGIN=True' or 'USE_SU_LOGIN=True' for # puppet.agent() as `puppet` is added to the path in # the .bash_profile. # We also expect a return code of: # 0=no changes or 2=changes applied puppet.agent( name="Run the puppet agent", success_exit_codes=[0, 2], )
install_chrony_node, install_compute, install_controller, install_network, install_openstack, install_telemetry, ) SUDO = True FAIL_PERCENT = 0 # Install base repos on all servers install_openstack() # Install the controller servers with state.limit(inventory.get_group('controllers')): install_chrony_controller() install_controller( dashboard=True, telemetry=True, placement=True, ) # Install the network/compute servers with state.limit(inventory.get_group('computes')): install_chrony_node() install_network() install_telemetry() install_compute( placement=True, telemetry=True,
'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 inventory admin_password = '******' rabbitmq_password = '******' keystone_password = '******' glance_password = '******' nova_password = '******' placement_password = '******' neutron_password = '******' ceilometer_password = '******' gnocchi_password = '******' metadata_secret = '01c61cc7aa38e2a96b8f3e9bb55a813fe78815b7' virt_type = 'qemu' bridge_interface = 'enp0s9' # The controllers group only contains one host controller_host = inventory.get_group('controllers')[0].data.ssh_hostname
config.SUDO = True # update the /etc/hosts file def update_hosts_file(name, ip): files.line( name="Add hosts to /etc/hosts", path="/etc/hosts", line=r" {}.example.com ".format(name), replace="{} {}.example.com {}".format(ip, name, name), ) # ensure all hosts are added to each /etc/hosts file masters = inventory.get_group("master_servers") for group_host in masters: update_hosts_file("master", group_host.get_fact(Ipv4Addresses)["eth0"]) agents = inventory.get_group("agent_servers") for group_host in agents: update_hosts_file("agent", group_host.get_fact(Ipv4Addresses)["eth0"]) if host in masters: server.hostname( name="Set the hostname for the Puppet Master", hostname="master.example.com", ) if host in agents: server.hostname(
config.SUDO = True # update the /etc/hosts file def update_hosts_file(name, ip): name = name.replace("@vagrant/", "") files.line( name="Add hosts to /etc/hosts", path="/etc/hosts", line=r" {}.example.com ".format(name), replace="{} {}.example.com {}".format(ip, name, name), ) # ensure all hosts are added to each /etc/hosts file inv = inventory.get_group("@vagrant") for item in inv: update_hosts_file(item.name, item.get_fact(Ipv4Addresses)["eth0"]) if host.name == "@vagrant/two": server.hostname( name="Set the hostname for two", hostname="two.example.com", ) if host.name == "@vagrant/one": server.hostname( name="Set the hostname for one", hostname="one.example.com", )