summaryrefslogtreecommitdiff
path: root/roles/monitoring/prometheus/exporter/register/tasks/main.yml
blob: 519975d610cfef6b84808b0954509a0c9f905024 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
---
- name: enable/disable job targets
  vars:
    job_targets: "{{ prometheus_server_jobs | prometheus_job_targets(hostvars[inventory_hostname]) }}"
    prometheus_target_labels: "{{ prometheus_target_labels_default | combine(prometheus_target_labels_extra) }}"
  block:
  - name: install files for enabled targets
    loop: "{{ job_targets | selectattr('enabled') }}"
    loop_control:
      loop_var: target
      label: "{{ target.job }} -> {{ target.instance }}"
    delegate_to: "{{ prometheus_server }}"
    template:
      src: "{{ lookup('first_found', {'paths': ['templates'], 'files': [target.job + '.yml.j2', 'generic.yml.j2']}) }}"
      dest: "/etc/prometheus/targets/{{ target.job }}/{{ target.instance }}.yml"
    notify: reload prometheus

  - name: remove files for disabled targets
    loop: "{{ job_targets | rejectattr('enabled') }}"
    loop_control:
      loop_var: target
      label: "{{ target.job }} -> {{ target.instance }}"
    delegate_to: "{{ prometheus_server }}"
    file:
      path: "/etc/prometheus/targets/{{ target.job }}/{{ target.instance }}.yml"
      state: absent
    notify: reload prometheus