From 8ea87b48c7d30f19325f82bac08ea153c82108cb Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Mon, 14 Oct 2019 11:12:58 +0100 Subject: [PATCH] Add extras directory to prometheus config All files within the directory are recursively templated. This provides a mechanism to include extra files that you can reference in prometheus.yml, for example: scape_targets: - job_name: ipmi params: module: default scrape_interval: 1m scrape_timeout: 30s metrics_path: /ipmi scheme: http file_sd_configs: - files: - /etc/prometheus/extras/file_sd/ipmi-exporter-targets.yml refresh_interval: 5m Change-Id: Ie2f085204b71725b901a179ee51541f1f383c6fa (cherry picked from commit cf6ef625f73696328881a660a48aac0f1f38fd2a) --- ansible/roles/prometheus/handlers/main.yml | 1 + ansible/roles/prometheus/tasks/config.yml | 46 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/ansible/roles/prometheus/handlers/main.yml b/ansible/roles/prometheus/handlers/main.yml index 0453ea7b70..85f7df3b26 100644 --- a/ansible/roles/prometheus/handlers/main.yml +++ b/ansible/roles/prometheus/handlers/main.yml @@ -19,6 +19,7 @@ - service.enabled | bool - config_json.changed | bool or prometheus_confs.changed | bool + or prometheus_extra_confs.changed | bool or prometheus_alerting_rules.changed | bool or prometheus_container.changed | bool diff --git a/ansible/roles/prometheus/tasks/config.yml b/ansible/roles/prometheus/tasks/config.yml index de52f25e41..70dde38c1f 100644 --- a/ansible/roles/prometheus/tasks/config.yml +++ b/ansible/roles/prometheus/tasks/config.yml @@ -248,6 +248,52 @@ notify: - Restart prometheus-jiralert container +- block: + - name: Find extra prometheus server config files + become: true + local_action: + module: find + paths: "{{ node_custom_config }}/prometheus/extras/" + patterns: "*" + recurse: true + register: prometheus_config_extras_result + run_once: true + + - name: Create subdirectories for extra config files + become: true + vars: + dirs: >- + {{ prometheus_config_extras_result.files | default([]) + | map(attribute='path') | map('dirname') | unique + | map('relpath', base) | list }} + file: + path: "{{ node_config_directory }}/prometheus-server/{{ item }}" + state: "directory" + owner: "{{ config_owner_user }}" + group: "{{ config_owner_group }}" + mode: "0770" + recurse: true + with_items: "{{ dirs }}" + + - name: Template extra prometheus server config files + become: true + vars: + relpath: "{{ item | relpath(base) }}" + template: + src: "{{ item }}" + dest: "{{ node_config_directory }}/prometheus-server/{{ relpath }}" + mode: "0660" + with_items: "{{ prometheus_config_extras_result.files | default([]) | map(attribute='path') | list }}" + register: prometheus_extra_confs + notify: + - Restart prometheus-server container + vars: + base: "{{ node_custom_config }}/prometheus/extras/" + service: "{{ prometheus_services['prometheus-server']}}" + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool + - name: Check prometheus containers become: true kolla_docker: