mirror of
https://github.com/prometheus-community/ansible
synced 2024-11-25 05:10:20 +00:00
allow to remove non-referenced custom rule files
Signed-off-by: Sergio Charpinel <sergio.charpinel@ebury.com>
This commit is contained in:
parent
2a37662a46
commit
e5d7fe3e78
3 changed files with 42 additions and 0 deletions
|
@ -101,6 +101,8 @@ prometheus_scrape_config_files:
|
|||
- prometheus/scrape_configs/*.yml
|
||||
- prometheus/scrape_configs/*.json
|
||||
|
||||
prometheus_provisioning_synced: false
|
||||
|
||||
# yamllint disable rule:line-length
|
||||
prometheus_alert_rules: # noqa yaml[line-length] # noqa line-length
|
||||
- alert: Watchdog
|
||||
|
|
|
@ -139,6 +139,11 @@ argument_specs:
|
|||
default:
|
||||
- "prometheus/rules/*.yml"
|
||||
- "prometheus/rules/*.yaml"
|
||||
prometheus_provisioning_synced:
|
||||
description:
|
||||
- "Should the provisioning of alert rule files be kept synced. If true, previous provisioned files will be removed if not referenced anymore."
|
||||
type: bool
|
||||
default: false
|
||||
prometheus_static_targets_files:
|
||||
description:
|
||||
- "List of folders where ansible will look for files containing custom static target configuration files which will be copied to C({{ prometheus_config_dir }}/file_sd/)."
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
when:
|
||||
- prometheus_alert_rules != []
|
||||
- not prometheus_agent_mode
|
||||
register: __rules_managed_copied
|
||||
notify:
|
||||
- reload prometheus
|
||||
become: true
|
||||
|
@ -82,6 +83,16 @@
|
|||
- configure
|
||||
- prometheus_configure
|
||||
|
||||
- name: Register previously copied rules
|
||||
ansible.builtin.find:
|
||||
paths: "{{ prometheus_config_dir }}/rules/"
|
||||
when: prometheus_provisioning_synced
|
||||
register: __rules_present
|
||||
tags:
|
||||
- prometheus
|
||||
- configure
|
||||
- prometheus_configure
|
||||
|
||||
- name: Copy custom alerting rule files
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item }}"
|
||||
|
@ -96,6 +107,30 @@
|
|||
notify:
|
||||
- reload prometheus
|
||||
become: true
|
||||
register: __rules_copied
|
||||
tags:
|
||||
- prometheus
|
||||
- configure
|
||||
- prometheus_configure
|
||||
|
||||
- name: Register present and copied rules
|
||||
ansible.builtin.set_fact:
|
||||
__rules_present_list: "{{ __rules_present | json_query('files[*].path') | default([]) }}"
|
||||
__rules_copied_list: "{{ __rules_copied | json_query('results[*].dest') | default([]) }}"
|
||||
__rules_managed_copied_list: "{{ [__rules_managed_copied | json_query('dest')] | default([]) }}"
|
||||
when: prometheus_provisioning_synced
|
||||
tags:
|
||||
- prometheus
|
||||
- configure
|
||||
- prometheus_configure
|
||||
|
||||
- name: "Remove rules not present on deployer machine (synchronize)"
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop: "{{ __rules_present_list | difference(__rules_copied_list) | difference(__rules_managed_copied_list) }}"
|
||||
become: true
|
||||
when: prometheus_provisioning_synced and not ansible_check_mode
|
||||
tags:
|
||||
- prometheus
|
||||
- configure
|
||||
|
|
Loading…
Reference in a new issue