Beispiel #1
0
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],
    )
Beispiel #2
0
    assert status is True  # ensure the command executed OK
    if 'Vagrant ' not in str(stdout):
        raise Exception(
            '`{}` did not work as expected.stdout:{} stderr:{}'.format(
                command, stdout, stderr))


if host.fact.linux_name == 'Ubuntu':

    apt.packages(
        {'Install required packages'},
        ['wget', 'unzip', 'python3'],
        update=True,
    )

    files.download(
        {'Download the Vagrantup Downloads page'},
        'https://www.vagrantup.com/downloads.html',
        '/tmp/downloads.html',
    )

    server.script_template(
        {'Use wget to download and unzip to /usr/local/bin'},
        'templates/download_vagrant.bash.j2',
    )

    python.call(
        {'Verify vagrant is installed by running version command'},
        verify_vagrant,
    )
Beispiel #3
0
    {'Create uberadmin group'},
    'uberadmin',
)

# multiple groups
for group in ['wheel', 'lusers']:
    server.group(
        {'Create the group {}'.format(group)},
        group,
    )

# To see output need to run pyinfra with '-v'
server.script(
    {'Hello'},
    'files/hello.bash',
)

# To see output need to run pyinfra with '-v'
some_var = 'blah blah blah '
server.script_template(
    {'Hello from script'},
    'templates/hello2.bash.j2',
    some_var=some_var,
)

# To see output need to run pyinfra with '-v'
server.shell(
    {'Say Hello'},
    'echo Hello',
)
Beispiel #4
0
    name='Create uberadmin group',
    group='uberadmin',
)

# multiple groups
for group in ['wheel', 'lusers']:
    server.group(
        name='Create the group {}'.format(group),
        group=group,
    )

# To see output need to run pyinfra with '-v'
server.script(
    name='Hello',
    src='files/hello.bash',
)

# To see output need to run pyinfra with '-v'
some_var = 'blah blah blah '
server.script_template(
    name='Hello from script',
    src='templates/hello2.bash.j2',
    some_var=some_var,
)

# To see output need to run pyinfra with '-v'
server.shell(
    name='Say Hello',
    commands='echo Hello',
)
Beispiel #5
0
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(
        name='Sign the agent, if needed',
        src='templates/sign_agent.bash.j2',
    )

if host in inventory.get_group('agent_servers'):

    init.systemd(
        name='Temp stop puppet agent so we can ensure a good run',
        service='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(
        name='Run the puppet agent',
        success_exit_codes=[0, 2],
    )
Beispiel #6
0
    name="Create uberadmin group",
    group="uberadmin",
)

# multiple groups
for group in ["wheel", "lusers"]:
    server.group(
        name="Create the group {}".format(group),
        group=group,
    )

# To see output need to run pyinfra with '-v'
server.script(
    name="Hello",
    src="files/hello.bash",
)

# To see output need to run pyinfra with '-v'
some_var = "blah blah blah "
server.script_template(
    name="Hello from script",
    src="templates/hello2.bash.j2",
    some_var=some_var,
)

# To see output need to run pyinfra with '-v'
server.shell(
    name="Say Hello",
    commands="echo Hello",
)
Beispiel #7
0
from pyinfra import config, host, inventory
from pyinfra.operations import init, puppet, server

config.SUDO = True
config.USE_SUDO_LOGIN = True

if host in inventory.get_group("master_servers"):
    server.script_template(
        name="Sign the agent, if needed",
        src="templates/sign_agent.bash.j2",
    )

if host in inventory.get_group("agent_servers"):

    init.systemd(
        name="Temp stop puppet agent so we can ensure a good run",
        service="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(
        name="Run the puppet agent",
        success_exit_codes=[0, 2],
    )