Exemplo n.º 1
0
def install_node_exporter(state, host):
    if not host.data.node_exporter_version:
        raise DeployError(
            'No node_exporter_version set for this host, refusing to install node_exporter!',
        )

    server.user(
        state,
        host,
        {'Create the node_exporter user (Called prometheus by default)'},
        '{{ host.data.node_exporter_user }}',
        shell='/sbin/nologin',
    )

    files.directory(
        state,
        host,
        {'Ensure the node_exporter install directory exists'},
        '{{ host.data.node_exporter_install_dir }}',
        user=host.data.node_exporter_user,
        group=host.data.node_exporter_user,
    )

    # Work out the filename
    host.data.node_exporter_version_name = (
        'node_exporter-{0}.linux-'
        'amd64' if host.fact.arch == 'x86_64' else host.fact.arch).format(
            host.data.node_exporter_version)

    host.data.node_exporter_temp_filename = state.get_temp_filename(
        'node_exporter-{0}'.format(host.data.node_exporter_version), )

    download_node_exporter = files.download(
        state,
        host,
        {'Download node_exporter'},
        ('{{ host.data.node_exporter_download_base_url }}/'
         'v{{ host.data.node_exporter_version }}/'
         '{{ host.data.node_exporter_version_name }}.tar.gz'),
        '{{ host.data.node_exporter_temp_filename }}',
    )

    # If we downloaded node_exporter, extract it!
    if download_node_exporter.changed:
        server.shell(
            state,
            host,
            {'Extract node_exporter'},
            'tar -xzf {{ host.data.node_exporter_temp_filename }}'
            ' -C {{ host.data.node_exporter_install_dir }}',
        )

    files.link(
        state,
        host,
        {'Symlink node_exporter to /usr/bin'},
        '{{ host.data.node_exporter_bin_dir }}/node_exporter',  # link
        '{{ host.data.node_exporter_install_dir }}/'
        '{{ host.data.node_exporter_version_name }}/node_exporter',
    )
Exemplo n.º 2
0
def brook(state: Optional[State] = None, host: Optional[Host] = None) -> None:
    """Install brook."""
    if host.fact.arch == "x86_64":
        files.download(
            source_url=
            "https://github.com/txthinking/brook/releases/download/v20200909/brook_linux_amd64",  # noqa: E950
            destination="/usr/local/bin/brook",
            mode=755,
            sha256sum=
            "efc4dc925bcaff4d33450fbcd02351da8f971f5cea6b84501a3d2a6f94876adf",  # noqa: E950
            state=state,
            host=host,
        )
        server.shell(
            f"nohup brook server -l {_get_host_ip(host.name)}:{environ['BROOK_PORT']} -p {environ['BROOK_PASSWORD']} > /dev/null 2> /dev/null &",  # noqa: B950
            success_exit_codes=[0, 1],
            state=state,
            host=host,
        )
    else:
        python.raise_exception(state, host, NotImplementedError)
Exemplo n.º 3
0
def install_prometheus(state, host):
    if not host.data.prometheus_version:
        raise DeployError(
            'No prometheus_version set for this host, refusing to install prometheus!',
        )

    server.user(
        state,
        host,
        {'Create the prometheus user'},
        '{{ host.data.prometheus_user }}',
        shell='/sbin/nologin',
    )

    files.directory(
        state,
        host,
        {'Ensure the prometheus data directory exists'},
        '{{ host.data.prometheus_data_dir }}',
        user=host.data.prometheus_user,
        group=host.data.prometheus_user,
    )

    files.directory(
        state,
        host,
        {'Ensure the prometheus install directory exists'},
        '{{ host.data.prometheus_install_dir }}',
        user=host.data.prometheus_user,
        group=host.data.prometheus_user,
    )

    # Work out the filename
    host.data.prometheus_version_name = ('prometheus-{0}.linux-'
                                         'amd64' if host.fact.arch == 'x86_64'
                                         else host.fact.arch).format(
                                             host.data.prometheus_version)

    host.data.prometheus_temp_filename = state.get_temp_filename(
        'prometheus-{0}'.format(host.data.prometheus_version), )

    download_prometheus = files.download(
        state,
        host,
        {'Download prometheus'},
        ('{{ host.data.prometheus_download_base_url }}/'
         'v{{ host.data.prometheus_version }}/'
         '{{ host.data.prometheus_version_name }}.tar.gz'),
        '{{ host.data.prometheus_temp_filename }}',
    )

    # If we downloaded prometheus, extract it!
    server.shell(
        state,
        host,
        {'Extract prometheus'},
        'tar -xzf {{ host.data.prometheus_temp_filename }} -C {{ host.data.prometheus_install_dir }}',
        when=download_prometheus.changed,
    )

    files.link(
        state,
        host,
        {'Symlink prometheus to /usr/bin'},
        '{{ host.data.prometheus_bin_dir }}/prometheus',  # link
        '{{ host.data.prometheus_install_dir }}/{{ host.data.prometheus_version_name }}/prometheus',
    )
Exemplo n.º 4
0
    files.template(
        {'Create a templated file'},
        'templates/default.j2',
        '/netboot/tftp/pxelinux.cfg/default',
        pxe_server=pxe_server,
    )

    # TODO: check sha
    # TODO: check pgp?
    # iso = 'ubuntu-18.04.3-desktop-amd64.iso'
    iso = 'ubuntu-18.04.3-live-server-amd64.iso'
    iso_full_path = '/tmp/{}'.format(iso)
    files.download(
        {'Download `{}` iso'.format(iso)},
        'http://releases.ubuntu.com/18.04/{}'.format(iso),
        iso_full_path,
    )

    server.shell(
        {'Mount iso'},
        'mount -o loop {} /mnt'.format(iso_full_path),
    )

    server.shell(
        {'Copy contents of ISO to mount'},
        'cp -Rfv /mnt/* /netboot/nfs/ubuntu1804/',
    )

    # copy vmlinuz and initrd files
    init_files = ['vmlinuz', 'initrd']
Exemplo n.º 5
0
    apt.packages(
        {'Install wget'},
        ['wget'],
        update=True,
    )

# Full URL:
# http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/alpine-netboot-3.11.2-x86_64.tar.gz
# sha256 is here
# http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/alpine-netboot-3.11.2-x86_64.tar.gz.sha256
tarfile = 'alpine-netboot-3.11.2-x86_64.tar.gz'
tarfile_full_path = '/tmp/{}'.format(tarfile)
sha256file = tarfile + '.sha256'
sha256file_full_path = '/tmp/{}'.format(sha256file)

# TODO: Check if download was successful
files.download(
    {'Download `{}`'.format(tarfile)},
    'http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/{}'.format(
        tarfile),
    tarfile_full_path,
)

files.download(
    {'Download `{}`'.format(sha256file)},
    'http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/{}'.format(
        sha256file),
    sha256file_full_path,
)
Exemplo n.º 6
0
from pyinfra import host
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
Exemplo n.º 7
0
        {'Install packages'},
        ['dnsmasq'],
        update=True,
    )

    tftp_dir = '/srv/tftp'
    files.directory(
        {'Ensure the `{}` exists'.format(tftp_dir)},
        tftp_dir,
    )

    tar_file = 'netboot.tar.gz'
    tar_file_full_path = '/tmp/{}'.format(tar_file)
    files.download(
        {'Download `{}`'.format(tar_file)},
        'http://archive.ubuntu.com/ubuntu/dists/bionic-updates/main/'
        'installer-amd64/current/images/netboot/{}'.format(tar_file),
        tar_file_full_path,
    )

    server.shell(
        {'Extract files from tar file'},
        'tar -xvzf {} -C {}'.format(tar_file_full_path, tftp_dir),
    )

    server.shell(
        {'Change permissions'},
        'chown -R nobody:nogroup {}'.format(tftp_dir),
    )

    uefi_file = 'grubnetx64.efi.signed'
    uefi_full_path = '{}/{}'.format(tftp_dir, uefi_file)
Exemplo n.º 8
0
        {'Install packages'},
        ['dnsmasq'],
        update=True,
    )

    tftp_dir = '/srv/tftp'
    files.directory(
        {'Ensure the `{}` exists'.format(tftp_dir)},
        tftp_dir,
    )

    tar_file = 'netboot.tar.gz'
    tar_file_full_path = '/tmp/{}'.format(tar_file)
    files.download(
        {'Download `{}`'.format(tar_file)},
        'http://archive.ubuntu.com/ubuntu/dists/bionic-updates/main/'
        'installer-amd64/current/images/netboot/{}'.format(tar_file),
        tar_file_full_path,
    )

    server.shell(
        {'Extract files from tar file'},
        'tar -xvzf {} -C {}'.format(tar_file_full_path, tftp_dir),
    )

    server.shell(
        {'Change permissions'},
        'chown -R nobody:nogroup {}'.format(tftp_dir),
    )

    # configure dnsmasq
    files.template(
Exemplo n.º 9
0
def install_etcd(state, host):
    if not host.data.etcd_version:
        raise DeployError(
            'No etcd_version set for this host, refusing to install etcd!', )

    server.user(
        state,
        host,
        {'Create the etcd user'},
        'etcd',
        shell='/sbin/nologin',
    )

    files.directory(
        state,
        host,
        {'Ensure the etcd data directory exists'},
        '{{ host.data.etcd_data_dir }}',
        user=host.data.etcd_user,
        group=host.data.etcd_user,
    )

    files.directory(
        state,
        host,
        {'Ensure the etcd install directory exists'},
        host.data.etcd_install_dir,
        user=host.data.etcd_user,
        group=host.data.etcd_user,
    )

    # Work out the filename
    host.data.etcd_version_name = ('etcd-{0}-linux-'
                                   'amd64' if host.fact.arch == 'x86_64' else
                                   host.fact.arch).format(
                                       host.data.etcd_version)

    host.data.etcd_temp_filename = state.get_temp_filename(
        'etcd-{0}'.format(host.data.etcd_version), )

    download_etcd = files.download(
        state,
        host,
        {'Download etcd'},
        ('{{ host.data.etcd_download_base_url }}/'
         '{{ host.data.etcd_version }}/'
         '{{ host.data.etcd_version_name }}.tar.gz'),
        '{{ host.data.etcd_temp_filename }}',
    )

    # If we downloaded etcd, extract it!
    server.shell(
        state,
        host,
        {'Extract etcd'},
        'tar -xzf {{ host.data.etcd_temp_filename }} -C {{ host.data.etcd_install_dir }}',
        when=download_etcd.changed,
    )

    files.link(
        state,
        host,
        {'Symlink etcd to /usr/bin'},
        '{{ host.data.etcd_bin_dir }}/etcd',  # link
        '{{ host.data.etcd_install_dir }}/{{ host.data.etcd_version_name }}/etcd',
    )

    files.link(
        state,
        host,
        {'Symlink etcdctl to {0}'.format(host.data.etcd_bin_dir)},
        '{{ host.data.etcd_bin_dir }}/etcdctl',
        '{{ host.data.etcd_install_dir }}/{{ host.data.etcd_version_name }}/etcdctl',
    )
Exemplo n.º 10
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,
    )