diff options
author | Christian Pointner <equinox@spreadspace.org> | 2021-09-26 04:29:02 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2021-09-26 04:29:02 +0200 |
commit | 223297c29d78e4fe95e2ed2338455708e4e0a9c3 (patch) | |
tree | 02534f529becf59835dd1ed5dee0f2321966a09b /roles/monitoring/prometheus/server/tasks | |
parent | switch to pascal for pressure (diff) | |
parent | fix alert wording (diff) |
Merge branch 'topic/prometheus-refactoring'
Diffstat (limited to 'roles/monitoring/prometheus/server/tasks')
-rw-r--r-- | roles/monitoring/prometheus/server/tasks/main.yml | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/roles/monitoring/prometheus/server/tasks/main.yml b/roles/monitoring/prometheus/server/tasks/main.yml index d0ccd8af..16167c9c 100644 --- a/roles/monitoring/prometheus/server/tasks/main.yml +++ b/roles/monitoring/prometheus/server/tasks/main.yml @@ -13,6 +13,7 @@ include_role: name: "storage/{{ prometheus_server_storage.type }}/volume" + ## TODO: pin version - name: install apt packages apt: name: prom-server @@ -37,50 +38,52 @@ - name: create configuration directories loop: - - jobs - rules - targets file: path: "/etc/prometheus/{{ item }}" state: directory -- name: create sub-directroy for all exporter types in jobs directory - loop: "{{ prometheus_server_jobs_generic + prometheus_server_jobs_special }}" +- name: create sub-directories for all jobs in targets directory + loop: "{{ prometheus_server_jobs }}" file: - path: "/etc/prometheus/jobs/{{ item }}" + path: "/etc/prometheus/targets/{{ item }}" state: directory -- name: generate generic targets config - loop: "{{ prometheus_zone_targets }}" - loop_control: - loop_var: target - template: - src: targets/generic.yml.j2 - dest: "/etc/prometheus/targets/{{ target }}.yml" - notify: reload prometheus +- name: enable/disable job targets + vars: + job_targets: "{{ hostvars | prometheus_job_targets(prometheus_server_jobs, prometheus_zone_targets) }}" + block: + - name: install files for enabled targets + loop: "{{ job_targets }}" + loop_control: + loop_var: target + label: "{{ target.job }} -> {{ target.instance }}" + when: target.enabled + template: + src: "{{ lookup('first_found', {'paths': ['templates/targets'], 'files': [target.job + '.yml.j2', 'generic.yml.j2']}) }}" + dest: "/etc/prometheus/targets/{{ target.job }}/{{ target.instance }}.yml" + notify: reload prometheus -- name: enable targets for generic jobs - loop: "{{ hostvars | prometheus_generic_job_targets(prometheus_server_jobs_generic, prometheus_zone_targets) }}" - loop_control: - label: "{{ item.job }} -> {{ item.instance }}" - file: - src: "{{ item.enabled | ternary('/etc/prometheus/targets/' + item.instance + '.yml', omit) }}" - path: "/etc/prometheus/jobs/{{ item.job }}/{{ item.instance }}.yml" - state: "{{ item.enabled | ternary('link', 'absent') }}" - notify: reload prometheus + - name: remove files for disabled targets + loop: "{{ job_targets }}" + loop_control: + loop_var: target + label: "{{ target.job }} -> {{ target.instance }}" + when: not target.enabled + file: + path: "/etc/prometheus/targets/{{ target.job }}/{{ target.instance }}.yml" + state: absent + notify: reload prometheus -- name: enable targets for special jobs - loop: "{{ hostvars | prometheus_special_job_targets(prometheus_server_jobs_special, prometheus_zone_targets) }}" - loop_control: - loop_var: target - label: "{{ target.job }} -> {{ target.instance }}" - template: - src: "targets/{{ target.job }}.yml.j2" - dest: "/etc/prometheus/jobs/{{ target.job }}/{{ target.instance }}.yml" - notify: reload prometheus +- name: create sub-directories for all jobs in rules directory + loop: "{{ prometheus_server_jobs | select('match', '.*/.*') | map('dirname') | unique }}" + file: + path: "/etc/prometheus/rules/{{ item }}" + state: directory - name: generate rules files for all jobs - loop: "{{ (prometheus_server_jobs_generic + prometheus_server_jobs_special) | union(['prometheus']) }}" + loop: "{{ prometheus_server_jobs | union(['prometheus']) }}" template: src: rules.yml.j2 dest: "/etc/prometheus/rules/{{ item }}.yml" |