Merge pull request #368 from manzsolutions-lpr/add-prometheus-scrape-config-files

feat: Added prometheus scrape_config_files support
This commit is contained in:
gardar 2024-05-29 12:45:52 +00:00 committed by GitHub
commit 9d34d42809
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 31 additions and 0 deletions

View file

@ -97,6 +97,10 @@ prometheus_static_targets_files:
- prometheus/targets/*.yml
- prometheus/targets/*.json
prometheus_scrape_config_files:
- prometheus/targets/*.yml
- prometheus/targets/*.json
# yamllint disable rule:line-length
prometheus_alert_rules: # noqa yaml[line-length] # noqa line-length
- alert: Watchdog

View file

@ -150,6 +150,15 @@ argument_specs:
default:
- "prometheus/targets/*.yml"
- "prometheus/targets/*.json"
prometheus_scrape_config_files:
description:
- "List of folders where ansible will look for files containing custom scrape config configuration files which will be copied to C({{ prometheus_config_dir }}/scrapes/)."
- "This feature is available starting from Prometheus v2.43.0."
type: "list"
elements: "str"
default:
- "prometheus/scrapes/*.yml"
- "prometheus/scrapes/*.json"
prometheus_system_group:
description:
- "System group for Prometheus."

View file

@ -70,3 +70,13 @@
group: "{{ prometheus_system_group }}"
mode: 0640
with_fileglob: "{{ prometheus_static_targets_files }}"
- name: Copy prometheus scrape config files
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ prometheus_config_dir }}/scrapes/"
force: true
owner: root
group: "{{ prometheus_system_group }}"
mode: 0640
with_fileglob: "{{ prometheus_scrape_config_files }}"

View file

@ -33,6 +33,7 @@
- "{{ prometheus_config_dir }}"
- "{{ prometheus_config_dir }}/rules"
- "{{ prometheus_config_dir }}/file_sd"
- "{{ prometheus_config_dir }}/scrapes"
- name: Get prometheus binary
when:

View file

@ -34,3 +34,10 @@ alerting:
scrape_configs:
{{ prometheus_scrape_configs | to_nice_yaml(indent=2,sort_keys=False) | indent(2,False) }}
{% if prometheus_version is version('2.43.0', '>=') %}
{% if prometheus_scrape_config_files != [] %}
scrape_config_files:
- scrapes/*
{% endif %}
{% endif %}