diff --git a/roles/prometheus/defaults/main.yml b/roles/prometheus/defaults/main.yml index e369e535..127e9696 100644 --- a/roles/prometheus/defaults/main.yml +++ b/roles/prometheus/defaults/main.yml @@ -90,7 +90,8 @@ prometheus_scrape_configs: prometheus_config_file: 'prometheus.yml.j2' prometheus_alert_rules_files: - - prometheus/rules/*.rules + - prometheus/rules/*.yml + - prometheus/rules/*.yaml prometheus_static_targets_files: - prometheus/targets/*.yml diff --git a/roles/prometheus/meta/argument_specs.yml b/roles/prometheus/meta/argument_specs.yml index a461d458..b57fd708 100644 --- a/roles/prometheus/meta/argument_specs.yml +++ b/roles/prometheus/meta/argument_specs.yml @@ -125,19 +125,20 @@ argument_specs: default: "prometheus.yml.j2" prometheus_alert_rules: description: - - "Full list of alerting rules which will be copied to C({{ prometheus_config_dir }}/rules/ansible_managed.rules)." - - "Alerting rules can be also provided by other files located in C({{ prometheus_config_dir }}/rules/) which have C(*.rules) extension" + - "Full list of alerting rules which will be copied to C({{ prometheus_config_dir }}/rules/ansible_managed.yml)." + - "Alerting rules can be also provided by other files located in C({{ prometheus_config_dir }}/rules/) which have a C(*.yml) or C(*.yaml) extension" - "Please see default values in role defaults/main.yml" type: "list" elements: "dict" prometheus_alert_rules_files: description: - "List of folders where ansible will look for files containing alerting rules which will be copied to C({{ prometheus_config_dir }}/rules/)." - - "Files must have C(*.rules) extension" + - "Files must have a C(*.yml) or C(*.yaml) extension" type: "list" elements: "str" default: - - "prometheus/rules/*.rules" + - "prometheus/rules/*.yml" + - "prometheus/rules/*.yaml" 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/)." diff --git a/roles/prometheus/molecule/alternative/tests/test_alternative.py b/roles/prometheus/molecule/alternative/tests/test_alternative.py index f9ce483c..f765cb37 100644 --- a/roles/prometheus/molecule/alternative/tests/test_alternative.py +++ b/roles/prometheus/molecule/alternative/tests/test_alternative.py @@ -27,7 +27,7 @@ def test_directories(host, dirs): "files", [ "/opt/prom/etc/prometheus.yml", - "/opt/prom/etc/rules/ansible_managed.rules", + "/opt/prom/etc/rules/ansible_managed.yml", "/opt/prom/etc/file_sd/node.yml", "/opt/prom/etc/file_sd/docker.yml", "/opt/prom/etc/scrape_configs/empty_scrapes.yml", diff --git a/roles/prometheus/molecule/default/tests/test_default.py b/roles/prometheus/molecule/default/tests/test_default.py index adf16841..a0742f4a 100644 --- a/roles/prometheus/molecule/default/tests/test_default.py +++ b/roles/prometheus/molecule/default/tests/test_default.py @@ -52,7 +52,7 @@ def test_files(host, files): @pytest.mark.parametrize("files", [ - "/etc/prometheus/rules/ansible_managed.rules" + "/etc/prometheus/rules/ansible_managed.yml" ]) def test_absent(host, files): f = host.file(files) diff --git a/roles/prometheus/tasks/configure.yml b/roles/prometheus/tasks/configure.yml index a2f949df..f6601373 100644 --- a/roles/prometheus/tasks/configure.yml +++ b/roles/prometheus/tasks/configure.yml @@ -65,8 +65,8 @@ - name: Alerting rules file ansible.builtin.template: - src: "alert.rules.j2" - dest: "{{ prometheus_config_dir }}/rules/ansible_managed.rules" + src: "ansible_managed.yml.j2" + dest: "{{ prometheus_config_dir }}/rules/ansible_managed.yml" owner: "{{ prometheus_system_user }}" group: "{{ prometheus_system_group }}" mode: 0640 diff --git a/roles/prometheus/tasks/preflight.yml b/roles/prometheus/tasks/preflight.yml index 12155eb9..f4ece365 100644 --- a/roles/prometheus/tasks/preflight.yml +++ b/roles/prometheus/tasks/preflight.yml @@ -73,6 +73,17 @@ - prometheus_alertmanager_config == [] - prometheus_alert_rules != [] +- name: Alert when alert rules files are found in the old .rules format + ansible.builtin.debug: + msg: > + prometheus_alert_rules_files contains rules in the old .rules file format. + This format has been deprecated in favour of the new YAML format since Prometheus v2.x. + You can update your rules using promtool: promtool update rules + + If your rules are already in the YAML format but with the .rules extension, you can safely ignore this message, + or rename the files to .yaml or .yml to get rid of it. + when: prometheus_alert_rules_files | select('search', '.rules$') | list | length > 0 + - name: Discover latest version ansible.builtin.set_fact: prometheus_version: "{{ (lookup('url', 'https://api.github.com/repos/{{ _prometheus_repo}}/releases/latest', headers=_github_api_headers, diff --git a/roles/prometheus/templates/alert.rules.j2 b/roles/prometheus/templates/ansible_managed.yml.j2 similarity index 100% rename from roles/prometheus/templates/alert.rules.j2 rename to roles/prometheus/templates/ansible_managed.yml.j2 diff --git a/roles/prometheus/templates/prometheus.yml.j2 b/roles/prometheus/templates/prometheus.yml.j2 index ba6be43c..8f569165 100644 --- a/roles/prometheus/templates/prometheus.yml.j2 +++ b/roles/prometheus/templates/prometheus.yml.j2 @@ -19,6 +19,8 @@ remote_read: {% if not prometheus_agent_mode and prometheus_alert_rules_files != [] %} rule_files: + - {{ prometheus_config_dir }}/rules/*.yml + - {{ prometheus_config_dir }}/rules/*.yaml - {{ prometheus_config_dir }}/rules/*.rules {% endif %}