Fix issues with Prometheus config generation

related to newly introduced merge mechanism.
1) Per-host overrides cannot be run_once.
2) Since merge_yaml is silent about missing files, it ignored
   the fact that no proper file was given due to wrong variable
   being referenced (see the closed bug).

Change-Id: I6db4af4c6e3364838bdae510f300038b0c1560b0
Closes-Bug: #1882460
This commit is contained in:
Radosław Piliszek 2020-06-15 10:41:57 +02:00
parent 03b6aaf3a7
commit d86f8ab9fe

View File

@ -56,24 +56,35 @@
notify: notify:
- Restart prometheus-server container - Restart prometheus-server container
- name: Find prometheus config overrides - name: Find prometheus common config overrides
find: find:
# NOTE(wszumski): Non-existent paths don't produce a failure # NOTE(wszumski): Non-existent paths don't produce a failure
paths: paths:
- "{{ node_custom_config }}/prometheus/prometheus.yml.d" - "{{ node_custom_config }}/prometheus/prometheus.yml.d"
patterns: "*.yml"
delegate_to: localhost
register: prometheus_common_config_overrides_result
run_once: true
- name: Find prometheus host config overrides
find:
# NOTE(wszumski): Non-existent paths don't produce a failure
paths:
- "{{ node_custom_config }}/prometheus/{{ inventory_hostname }}/prometheus.yml.d" - "{{ node_custom_config }}/prometheus/{{ inventory_hostname }}/prometheus.yml.d"
patterns: "*.yml" patterns: "*.yml"
delegate_to: localhost delegate_to: localhost
register: prometheus_config_overrides_result register: prometheus_host_config_overrides_result
run_once: true # NOTE(yoctozepto): this cannot be run_once
run_once: false
- name: Copying over prometheus config file - name: Copying over prometheus config file
become: true become: true
vars: vars:
service: "{{ prometheus_services['prometheus-server'] }}" service: "{{ prometheus_services['prometheus-server'] }}"
overrides: "{{ prometheus_config_overrides_result.files | map(attribute='path') | list }}" common_overrides: "{{ prometheus_common_config_overrides_result.files | map(attribute='path') | list }}"
host_overrides: "{{ prometheus_host_config_overrides_result.files | map(attribute='path') | list }}"
merge_yaml: merge_yaml:
sources: "{{ [prometheus_config_file] + overrides }}" sources: "{{ [item] + common_overrides + host_overrides }}"
dest: "{{ node_config_directory }}/prometheus-server/prometheus.yml" dest: "{{ node_config_directory }}/prometheus-server/prometheus.yml"
mode: "0660" mode: "0660"
extend_lists: true extend_lists: true