fix(config): cope with aberrant service names

This commit is contained in:
Alexander Weidinger 2019-10-04 12:13:24 +02:00
parent 333249374e
commit 0a3384222c
6 changed files with 50 additions and 9 deletions

View File

@ -46,9 +46,17 @@ prometheus-config-args-{{ name }}-all:
{%- elif grains.os_family != 'FreeBSD' %}
{%- set args_file = prometheus.pkg.get(name, {}).get('args_file', False) %}
{%- if not args_file %}
{%- set args_file = prometheus.dir.args | path_join(name) %}
{%- if not grains.os_family in ['Debian'] %}
{%- set args_file = "{}.sh".format(args_file) %}
{%- endif %}
{%- endif %}
prometheus-config-args-{{ name }}-file-absent:
file.absent:
- name: {{ prometheus.dir.args }}/{{ name }}.sh
- name: {{ args_file }}
- require:
- service: prometheus-service-clean-{{ name }}-service-dead
- require_in:

View File

@ -94,9 +94,17 @@ prometheus-config-args-{{ name }}-all:
{%- elif grains.os_family != 'FreeBSD' %}
{%- set args_file = prometheus.pkg.get(name, {}).get('args_file', False) %}
{%- if not args_file %}
{%- set args_file = prometheus.dir.args | path_join(name) %}
{%- if not grains.os_family in ['Debian'] %}
{%- set args_file = "{}.sh".format(args_file) %}
{%- endif %}
{%- endif %}
prometheus-config-args-{{ name }}-file-managed:
file.managed:
- name: {{ prometheus.dir.args }}/{{ name }}.sh
- name: {{ args_file }}
- contents: |
ARGS="{{ concat_args(args) }}"
- watch_in:

View File

@ -10,7 +10,14 @@
# you will need to provide at least an empty dict in this file, e.g.
# osfamilymap: {}
---
Debian: {}
Debian:
pkg:
node_exporter:
name: prometheus-node-exporter
args_file: /etc/default/prometheus-node-exporter
service:
node_exporter:
name: prometheus-node-exporter
RedHat:
pkg:

View File

@ -8,12 +8,17 @@
{%- for name in prometheus.wanted %}
{%- if name in prometheus.service %}
{%- set service_name = prometheus.service.get(name, {}).get('name', False) %}
{%- if not service_name %}
{%- set service_name = name %}
{%- endif %}
prometheus-service-clean-{{ name }}-service-dead:
service.dead:
- name: {{ name }}
- enable: False
{%- if grains.kernel|lower == 'linux' %}
- onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1
- onlyif: systemctl list-units | grep {{ service_name }} >/dev/null 2>&1
{%- endif %}
file.absent:
- name: {{ prometheus.dir.service }}/{{ name }}.service

View File

@ -23,20 +23,26 @@ prometheus-config-file-var-file-directory:
{%- for name in prometheus.wanted %}
{%- if name in prometheus.service %}
{%- set service_name = prometheus.service.get(name, {}).get('name', False) %}
{%- if not service_name %}
{%- set service_name = name %}
{%- endif %}
{%- if grains.kernel|lower == 'linux' %}
prometheus-service-running-{{ name }}-service-unmasked:
service.unmasked:
- name: {{ name }}
- name: {{ service_name }}
- require:
- file: prometheus-config-file-var-file-directory
- onlyif:
- systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1
- systemctl list-units | grep {{ service_name }} >/dev/null 2>&1
{%- endif %}
prometheus-service-running-{{ name }}-service-running:
service.running:
- name: {{ name }}
- name: {{ service_name }}
- enable: True
{%- if name in prometheus.config %}
- watch:
@ -46,7 +52,7 @@ prometheus-service-running-{{ name }}-service-running:
- file: prometheus-config-file-var-file-directory
{%- if grains.kernel|lower == 'linux' %}
- service: prometheus-service-running-{{ name }}-service-unmasked
- onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1
- onlyif: systemctl list-units | grep {{ service_name }} >/dev/null 2>&1
{%- endif %}
{%- endif %}

View File

@ -1,7 +1,14 @@
control 'prometheus configuration environment' do
title 'should match desired lines'
describe file('/etc/default/prometheus.sh') do
args_file = case os[:family]
when 'debian'
'/etc/default/prometheus'
else
'/etc/default/prometheus.sh'
end
describe file(args_file) do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }