def configure_node_exporter(state, host, enable_service=True, extra_args=None): op_name = 'Ensure node_exporter service is running' if enable_service: op_name = '{0} and enabled'.format(op_name) if host.fact.linux_distribution['major'] >= 16: # Setup node_exporter init generate_service = files.template( name='Upload the node_exporter systemd unit file', src=get_template_path('node_exporter.service.j2'), dest='/etc/systemd/system/node_exporter.service', extra_args=extra_args, state=state, host=host, ) init.systemd( name=op_name, service='node_exporter', running=True, restarted=generate_service.changed, daemon_reload=generate_service.changed, enabled=enable_service, state=state, host=host, ) elif host.fact.linux_distribution['major'] == 14: generate_service = files.template( name='Upload the node_exporter init.d file', src=get_template_path('init.d.j2'), dest='/etc/init.d/node_exporter', mode=755, ex_name='node_exporter', ex_bin_dir=host.data.node_exporter_bin_dir, ex_user=host.data.node_exporter_user, extra_args=extra_args, state=state, host=host, ) # Start (/enable) the prometheus service init.d( name=op_name, service='node_exporter', running=True, restarted=generate_service.changed, reloaded=generate_service.changed, enabled=enable_service, state=state, host=host, )
from pyinfra.operations import init SUDO = True init.d( {'Restart and enable rsyslog'}, 'rsyslog', restarted=True, enabled=True, ) init.d_enable( {'Finer control on which runlevels rsyslog should run'}, 'rsyslog', start_levels=(3, 4, 5), stop_levels=(0, 1, 2, 6), ) init.service( {'Enable open-vm-tools service'}, 'open-vm-tools', enabled=True, )
def configure_prometheus(state, host, enable_service=True, extra_args=None): # Configure prometheus generate_config = files.template( name='Upload the prometheus config file', src=get_template_path('prometheus.yml.j2'), dest='/etc/default/prometheus.yml', state=state, host=host, ) op_name = 'Ensure prometheus service is running' if enable_service: op_name = '{0} and enabled'.format(op_name) restart = generate_config.changed if extra_args and ('--web.enable-lifecycle' in extra_args): restart = False hit_reload_endpoint = True else: hit_reload_endpoint = False # Setup prometheus init if host.fact.linux_distribution['major'] >= 16: generate_service = files.template( name='Upload the prometheus systemd unit file', src=get_template_path('prometheus.service.j2'), dest='/etc/systemd/system/prometheus.service', extra_args=extra_args, state=state, host=host, ) # Start (/enable) the prometheus service init.systemd( name=op_name, service='prometheus', running=True, restarted=restart, enabled=enable_service, daemon_reload=generate_service.changed, state=state, host=host, ) # This has to happen after the service reload if hit_reload_endpoint: server.shell( commands='curl -X POST http://localhost:9090/-/reload', state=state, host=host, ) elif host.fact.linux_distribution['major'] == 14: generate_service = files.template( name='Upload the prometheus init.d file', src=get_template_path('init.d.j2'), dest='/etc/init.d/prometheus', extra_args=extra_args, state=state, host=host, ) # Start (/enable) the prometheus service init.d( name=op_name, service='prometheus', running=True, restarted=restart, reloaded=generate_service.changed, enabled=enable_service, state=state, host=host, )
def configure_exporter( state, host, ex_url, ex_user='******', ex_bin_dir='/usr/local/bin', enable_service=True, extra_args=None, ): ex_name, ex_bin_name = _get_names(ex_url) # Start (/enable) the node_exporter service op_name = 'Ensure exporter service is running' if enable_service: op_name = '{0} and enabled'.format(op_name) if host.fact.linux_distribution['major'] >= 16: # Setup node_exporter init generate_service = files.template( name='Upload the {} systemd unit file'.format(ex_name), src=get_template_path('exporter.service.j2'), dest='/etc/systemd/system/{}.service'.format(ex_bin_name), ex_name=ex_name, ex_bin_dir=ex_bin_dir, ex_user=ex_user, extra_args=extra_args, state=state, host=host, ) init.systemd( name=op_name, service=ex_bin_name, running=True, restarted=generate_service.changed, reloaded=generate_service.changed, enabled=enable_service, daemon_reload=generate_service.changed, state=state, host=host, ) elif host.fact.linux_distribution['major'] == 14: generate_service = files.template( name='Upload the {} init.d file'.format(ex_name), src=get_template_path('init.d.j2'), dest='/etc/init.d/{}'.format(ex_name), mode=755, ex_name=ex_name, ex_bin_dir=ex_bin_dir, ex_user=ex_user, extra_args=extra_args, state=state, host=host, ) # Start (/enable) the prometheus service init.d( name=op_name, service=ex_name, running=True, restarted=generate_service.changed, reloaded=generate_service.changed, enabled=enable_service, state=state, host=host, )
from pyinfra.operations import init SUDO = True init.d( name='Restart and enable rsyslog', service='rsyslog', restarted=True, enabled=True, ) init.d_enable( name='Finer control on which runlevels rsyslog should run', service='rsyslog', start_levels=(3, 4, 5), stop_levels=(0, 1, 2, 6), ) init.service( name='Enable open-vm-tools service', service='open-vm-tools', enabled=True, )
from pyinfra.operations import init init.d( name="Restart and enable rsyslog", service="rsyslog", restarted=True, enabled=True, ) init.d_enable( name="Finer control on which runlevels rsyslog should run", service="rsyslog", start_levels=(3, 4, 5), stop_levels=(0, 1, 2, 6), ) init.service( name="Enable open-vm-tools service", service="open-vm-tools", enabled=True, )