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', )
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', )
{'Download a file from a remote'}, '/etc/os-release', '/tmp/whocares', ) foo_variable = 'This is some foo variable contents' files.template( {'Create a templated file'}, 'templates/foo.j2', '/tmp/foo', foo_variable=foo_variable, ) files.link( {'Create link /etc/issue2 that points to /etc/issue'}, '/etc/issue2', '/etc/issue', ) # Note: The directory /tmp/secret will get created with the default umask. files.file( {'Create /tmp/secret/file'}, '/tmp/secret/file', mode='600', user='******', group='root', touch=True, create_remote_dir=True, ) files.directory(
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', )
'templates/myweb.service.j2', '/etc/systemd/system/myweb.service', mode='755', user='******', group='root', ) files.template( {'Create index.html'}, 'templates/index.html.j2', '/web/index.html', ) files.link( {'Create link /web/index.htm that points to /web/index.html'}, '/web/index.htm', '/web/index.html', ) # Note: Allowing sudo to python is not a very secure. files.line( {'Ensure myweb can run /usr/bin/python3 without password'}, '/etc/sudoers', r'myweb .*', replace='myweb ALL=(ALL) NOPASSWD: /usr/bin/python3', ) server.shell( {'Check that sudoers file is ok'}, 'visudo -c', )