Esempio n. 1
0
def deploy_docker(state, host, config=None):
    '''
    Install Docker on the target machine.

    Args:
        config: filename or dict of JSON data
    '''

    # Fail early!
    if not host.fact.deb_packages and not host.fact.rpm_packages:
        raise DeployError((
            'Neither apt or yum were found, '
            'pyinfra-docker cannot provision this machine!'
        ))

    # Install Docker w/apt or yum
    if host.fact.deb_packages:
        _apt_install(state, host)

    if host.fact.rpm_packages:
        _yum_install(state, host)

    config_file = config

    # If config is a dictionary, turn it into a JSON file for the config
    if isinstance(config, dict):
        config_hash = make_hash(config)

        # Convert any jinja2 string variables ({{ host.data...}})
        config = get_arg_value(state, host, config)

        # Turn into a file-like object and name such that we only generate one
        # operation hash between multiple hosts (with the same config).
        config_file = StringIO(json.dumps(config))
        config_file.__name__ = config_hash

    if config:
        files.directory(
            state, host,
            {'Ensure /etc/docker exists'},
            '/etc/docker',
        )

        files.put(
            state, host,
            {'Upload the Docker daemon.json'},
            config_file,
            '/etc/docker/daemon.json',
        )
Esempio n. 2
0
def install_nova_node(state,
                      host,
                      neutron=False,
                      placement=False,
                      ceilometer=False):
    apt.packages(
        state,
        host,
        {'Install nova-compute'},
        ['nova-compute'],
    )

    files.put(
        {'Upload interface.j2'},
        get_template_path('interfaces.j2'),
        '/etc/nova/interfaces.j2',
    )

    nova_configure = files.template(
        state,
        host,
        {'Generate nova config'},
        get_template_path('nova-node.conf.j2'),
        '/etc/nova/nova.conf',
        neutron=neutron,
        placement=placement,
        ceilometer=ceilometer,
    )

    nova_compute_configure = files.template(
        state,
        host,
        {'Generate nova-compute config'},
        get_template_path('nova-compute.conf.j2'),
        '/etc/nova/nova-compute.conf',
    )

    init.service(
        state,
        host,
        {'Restart nova-compute'},
        'nova-compute',
        restarted=nova_configure.changed or nova_compute_configure.changed,
    )
Esempio n. 3
0
    {'Create the pyinfra_stuff database'},
    'pyinfra_stuff',
    owner='pyinfra',
    encoding='UTF8',
    sudo_user='******',
)


# Upload & import a SQL file into the pyinfra_stuff database
#

filename = 'files/a_db.sql'
temp_filename = state.get_temp_filename(filename)

files.put(
    {'Upload the a_db.sql file'},
    filename, temp_filename,
)

postgresql.load(
    {'Import the uploaded a_db.sql file'},
    temp_filename,
    database='pyinfra_stuff',
    sudo_user='******',
)


# Now duplicate the pyinfra_stuff database -> pyinfra_stuff_copy
#

postgresql.database(
    {'Create the pyinfra_stuff_copy database'},
Esempio n. 4
0
# Ensure the state of directories
files.directory(
    host.data.env_dir,
    user='******',
    group='pyinfra',
    mode=755,
    recursive=True,
    sudo=True,
    serial=True,
)

# Copy local files to remote host
files.put(
    'files/file.txt',
    '/home/vagrant/file.txt',
    mode=777,
)
# and sync directories
files.sync(
    'files',
    '/home/vagrant/example_files',
    user='******',
    group='pyinfra',
    delete=True,
    sudo=True,
)

# Generate files from local jinja2 templates
files.template(
    'templates/template.txt.j2',
Esempio n. 5
0
from pyinfra.modules import files

# Note: This requires files in the files/ directory.

SUDO = True

if host.fact.linux_name in ['CentOS', 'RedHat']:
    files.download(
        {'Download the Docker repo file'},
        'https://download.docker.com/linux/centos/docker-ce.repo',
        '/etc/yum.repos.d/docker-ce.repo',
    )

files.put(
    {'Update the message of the day file'},
    'files/motd',
    '/etc/motd',
    mode='644',
)

# prepare to do some maintenance
maintenance_line = 'SYSTEM IS DOWN FOR MAINTENANCE'
# files.line(
#     {'Add the down-for-maintenance line in /etc/motd'},
#     '/etc/motd',
#     maintenance_line,
# )

# do some maintenance...
# Then, after the maintenance is done, remove the maintenance line
files.line(
    {'Remove the down-for-maintenance line in /etc/motd'},
Esempio n. 6
0
from pyinfra.modules import files, server

CONNECT_TIMEOUT = 1
FAIL_PERCENT = 0

server.user(
    {'Add pyinfra user'},
    'pyinfra',
    home='/home/pyinfra',
    shell='/bin/bash',
)

files.file(
    {'Add log file'},
    '/var/log/pyinfra.log',
    user='******',
    mode=777,
)

files.put(
    {'Copy a file'},
    '../files/test_file.txt',
    '/home/pyinfra/test_file.txt',
    user='******',
)

server.shell(
    {'Run some shell'},
    'echo "hi!"',
)
Esempio n. 7
0
os.chdir(os.path.dirname('./' + __file__))
cwd = os.path.abspath('.')
project_root = os.path.abspath('../..')

apt.packages(
    {'Install prometheus'},
    ['prometheus'],
    latest=True,
    sudo=True,
)

files.put(
    {'Install prometheus config'},
    'prometheus.yml',
    '/etc/prometheus/prometheus.yml',
    mode='644',
    user='******',
    group='root',
    sudo=True,
)

init.systemd(
    {'Restart prometheus service'},
    'prometheus',
    running=True,
    restarted=True,
    enabled=True,
    sudo=True,
)
Esempio n. 8
0
    {'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,
)

# Executing with sudo
#

# Ensure the state of a user
server.user(
Esempio n. 9
0
check_call(['go', 'install', 'hockeypuck/...'], cwd=project_root)
files.sync(
    {'Install hockeypuck binaries'},
    project_root + '/bin',
    '/usr/bin',
    mode='755',
    user='******',
    group='root',
    sudo=True,
)

files.put(
    {'Install hockeypuck service'},
    project_root + '/debian/hockeypuck.service',
    '/etc/systemd/system/hockeypuck.service',
    mode='644',
    user='******',
    group='root',
    sudo=True,
)

files.template(
    {'Configure hockeypuck'},
    'hockeypuck.conf',
    '/etc/hockeypuck/hockeypuck.conf',
    mode='644',
    sudo=True,
    peers=host.data.peers,
)

apt.packages(