Beispiel #1
0
# Ensure the state of a user
server.user(
    {'Ensure pyinfra user exists'},
    'pyinfra',
    shell='/bin/sh',

    # Global arguments available in all operations, for the full list see:
    # https://pyinfra.readthedocs.io/page/deploys.html#global-arguments
    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(
Beispiel #2
0
    # Options available for all operations
    sudo=True,
    sudo_user='******',
    ignore_errors=False,
    serial=False,
    run_once=False,
    get_pty=False,
    timeout=30,  # only applies to commands on the remote host (not SFTP, local Python)
    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,
Beispiel #3
0
        ['cron'],
        update=True,
    )

# simple example for a crontab
server.crontab(
    {'Backup /etc weekly'},
    '/bin/tar cf /tmp/etc_bup.tar /etc',
    name='backup_etc',
    day_of_week=0,
    hour=1,
    minute=0,
)

server.group(
    {'Create docker group'},
    'docker',
)

# if we are not running inside a docker container
if not host.fact.file('/.dockerenv'):

    # Cannot change hostname if running in a docker container
    server.hostname(
        {'Set the hostname'},
        'server1.example.com',
    )

    # Cannot change value on read-only filesystem
    # use "/sbin/sysctl -a | grep file-max" to check value
    server.sysctl(
        {'Change the fs.file-max value'},