fix(config): cope with aberrant service names
This commit is contained in:
parent
333249374e
commit
0a3384222c
@ -46,9 +46,17 @@ prometheus-config-args-{{ name }}-all:
|
|||||||
|
|
||||||
{%- elif grains.os_family != 'FreeBSD' %}
|
{%- 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:
|
prometheus-config-args-{{ name }}-file-absent:
|
||||||
file.absent:
|
file.absent:
|
||||||
- name: {{ prometheus.dir.args }}/{{ name }}.sh
|
- name: {{ args_file }}
|
||||||
- require:
|
- require:
|
||||||
- service: prometheus-service-clean-{{ name }}-service-dead
|
- service: prometheus-service-clean-{{ name }}-service-dead
|
||||||
- require_in:
|
- require_in:
|
||||||
|
@ -94,9 +94,17 @@ prometheus-config-args-{{ name }}-all:
|
|||||||
|
|
||||||
{%- elif grains.os_family != 'FreeBSD' %}
|
{%- 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:
|
prometheus-config-args-{{ name }}-file-managed:
|
||||||
file.managed:
|
file.managed:
|
||||||
- name: {{ prometheus.dir.args }}/{{ name }}.sh
|
- name: {{ args_file }}
|
||||||
- contents: |
|
- contents: |
|
||||||
ARGS="{{ concat_args(args) }}"
|
ARGS="{{ concat_args(args) }}"
|
||||||
- watch_in:
|
- watch_in:
|
||||||
|
@ -10,7 +10,14 @@
|
|||||||
# you will need to provide at least an empty dict in this file, e.g.
|
# you will need to provide at least an empty dict in this file, e.g.
|
||||||
# osfamilymap: {}
|
# 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:
|
RedHat:
|
||||||
pkg:
|
pkg:
|
||||||
|
@ -8,12 +8,17 @@
|
|||||||
{%- for name in prometheus.wanted %}
|
{%- for name in prometheus.wanted %}
|
||||||
{%- if name in prometheus.service %}
|
{%- 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:
|
prometheus-service-clean-{{ name }}-service-dead:
|
||||||
service.dead:
|
service.dead:
|
||||||
- name: {{ name }}
|
- name: {{ name }}
|
||||||
- enable: False
|
- enable: False
|
||||||
{%- if grains.kernel|lower == 'linux' %}
|
{%- 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 %}
|
{%- endif %}
|
||||||
file.absent:
|
file.absent:
|
||||||
- name: {{ prometheus.dir.service }}/{{ name }}.service
|
- name: {{ prometheus.dir.service }}/{{ name }}.service
|
||||||
|
@ -23,20 +23,26 @@ prometheus-config-file-var-file-directory:
|
|||||||
|
|
||||||
{%- for name in prometheus.wanted %}
|
{%- for name in prometheus.wanted %}
|
||||||
{%- if name in prometheus.service %}
|
{%- 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' %}
|
{%- if grains.kernel|lower == 'linux' %}
|
||||||
|
|
||||||
prometheus-service-running-{{ name }}-service-unmasked:
|
prometheus-service-running-{{ name }}-service-unmasked:
|
||||||
service.unmasked:
|
service.unmasked:
|
||||||
- name: {{ name }}
|
- name: {{ service_name }}
|
||||||
- require:
|
- require:
|
||||||
- file: prometheus-config-file-var-file-directory
|
- file: prometheus-config-file-var-file-directory
|
||||||
- onlyif:
|
- onlyif:
|
||||||
- systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1
|
- systemctl list-units | grep {{ service_name }} >/dev/null 2>&1
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
prometheus-service-running-{{ name }}-service-running:
|
prometheus-service-running-{{ name }}-service-running:
|
||||||
service.running:
|
service.running:
|
||||||
- name: {{ name }}
|
- name: {{ service_name }}
|
||||||
- enable: True
|
- enable: True
|
||||||
{%- if name in prometheus.config %}
|
{%- if name in prometheus.config %}
|
||||||
- watch:
|
- watch:
|
||||||
@ -46,7 +52,7 @@ prometheus-service-running-{{ name }}-service-running:
|
|||||||
- file: prometheus-config-file-var-file-directory
|
- file: prometheus-config-file-var-file-directory
|
||||||
{%- if grains.kernel|lower == 'linux' %}
|
{%- if grains.kernel|lower == 'linux' %}
|
||||||
- service: prometheus-service-running-{{ name }}-service-unmasked
|
- 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 %}
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
control 'prometheus configuration environment' do
|
control 'prometheus configuration environment' do
|
||||||
title 'should match desired lines'
|
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_file }
|
||||||
it { should be_owned_by 'root' }
|
it { should be_owned_by 'root' }
|
||||||
it { should be_grouped_into 'root' }
|
it { should be_grouped_into 'root' }
|
||||||
|
Loading…
Reference in New Issue
Block a user