|
1 | 1 | --- |
2 | | -- name: Validate PBS exporter instances list |
| 2 | +- name: Validate PBS exporter targets list |
3 | 3 | ansible.builtin.assert: |
4 | 4 | that: |
5 | | - - pbs_exporter_instances is defined |
6 | | - - pbs_exporter_instances is sequence |
7 | | - - pbs_exporter_instances is not string |
8 | | - - pbs_exporter_instances | length > 0 |
9 | | - fail_msg: >- |
10 | | - pbs_exporter_instances must be a non-empty inventory list. |
| 5 | + - pbs_exporter_targets is defined |
| 6 | + - pbs_exporter_targets is sequence |
| 7 | + - pbs_exporter_targets is not string |
| 8 | + - pbs_exporter_targets | length > 0 |
| 9 | + fail_msg: pbs_exporter_targets must be a non-empty inventory list. |
11 | 10 | no_log: true |
12 | 11 |
|
13 | | -- name: Validate PBS exporter instances |
| 12 | +- name: Validate PBS exporter targets |
14 | 13 | ansible.builtin.assert: |
15 | 14 | that: |
16 | | - - item.name is defined |
17 | | - - item.name is string |
18 | | - - item.name is match('^[a-z0-9][a-z0-9-]*$') |
19 | 15 | - item.netbox_name is defined |
20 | 16 | - item.netbox_name is string |
21 | 17 | - item.netbox_name | length > 0 |
| 18 | + - item.target is defined |
| 19 | + - item.target is string |
| 20 | + - item.target | length > 0 |
22 | 21 | - item.api_token_id is defined |
23 | 22 | - item.api_token_id is string |
24 | 23 | - item.api_token_id | length > 0 |
25 | 24 | - item.api_token_secret is defined |
26 | 25 | - item.api_token_secret is string |
27 | 26 | - item.api_token_secret | length > 0 |
28 | 27 | fail_msg: >- |
29 | | - Every PBS exporter instance must define a lowercase name, netbox_name, |
30 | | - api_token_id, and api_token_secret. |
31 | | - loop: "{{ pbs_exporter_instances }}" |
| 28 | + Every PBS exporter target must define netbox_name, target, api_token_id, |
| 29 | + and api_token_secret. |
| 30 | + loop: "{{ pbs_exporter_targets }}" |
32 | 31 | loop_control: |
33 | 32 | label: hidden |
34 | 33 | no_log: true |
35 | 34 |
|
36 | | -- name: Validate unique PBS exporter instance selectors |
| 35 | +- name: Validate unique PBS exporter target selectors |
37 | 36 | ansible.builtin.assert: |
38 | 37 | that: |
39 | 38 | - >- |
40 | | - pbs_exporter_instances | map(attribute='name') | unique | list | length |
41 | | - == pbs_exporter_instances | length |
| 39 | + pbs_exporter_targets | map(attribute='netbox_name') | unique | list | length |
| 40 | + == pbs_exporter_targets | length |
42 | 41 | - >- |
43 | | - pbs_exporter_instances | map(attribute='netbox_name') | unique | list | length |
44 | | - == pbs_exporter_instances | length |
45 | | - fail_msg: PBS exporter instance names and NetBox names must be unique. |
| 42 | + pbs_exporter_targets | map(attribute='target') | unique | list | length |
| 43 | + == pbs_exporter_targets | length |
| 44 | + fail_msg: PBS exporter NetBox names and targets must be unique. |
| 45 | + no_log: true |
| 46 | + |
| 47 | +- name: Create PBS exporter config directory |
| 48 | + ansible.builtin.file: |
| 49 | + path: "{{ docker.dir.config }}/prometheus_pbs_exporter" |
| 50 | + state: directory |
| 51 | + owner: root |
| 52 | + group: root |
| 53 | + mode: "0700" |
46 | 54 | no_log: true |
47 | 55 |
|
48 | | -- name: Remove legacy Prometheus PBS exporter |
| 56 | +- name: Render PBS exporter targets |
| 57 | + ansible.builtin.template: |
| 58 | + src: pbs_targets.yml.j2 |
| 59 | + dest: "{{ docker.dir.config }}/prometheus_pbs_exporter/targets.yml" |
| 60 | + owner: root |
| 61 | + group: root |
| 62 | + mode: "0600" |
| 63 | + no_log: true |
| 64 | + |
| 65 | +- name: Remove legacy per-target PBS exporters |
49 | 66 | community.docker.docker_container: |
50 | | - name: prometheus-pbs_exporter |
| 67 | + name: "prometheus-pbs-exporter-{{ item.name }}" |
51 | 68 | state: absent |
| 69 | + loop: "{{ pbs_exporter_instances | default([]) }}" |
| 70 | + loop_control: |
| 71 | + label: hidden |
52 | 72 | no_log: true |
53 | 73 |
|
54 | | -- name: Setup Prometheus PBS exporters |
| 74 | +- name: Setup Prometheus PBS exporter |
55 | 75 | community.docker.docker_container: |
56 | | - name: "prometheus-pbs-exporter-{{ item.name }}" |
| 76 | + name: prometheus-pbs_exporter |
57 | 77 | image: "{{ pbs_exporter_image | default('natrontech/pbs-exporter:latest') }}" |
58 | 78 | networks: |
59 | 79 | - name: monitoring |
60 | 80 | dns_servers: "{{ dns.servers }}" |
61 | | - env: |
62 | | - PBS_TOKEN_ID: "{{ item.api_token_id }}" |
63 | | - PBS_TOKEN_SECRET: "{{ item.api_token_secret }}" |
64 | | - PBS_TLS_INSECURE: "true" |
| 81 | + volumes: |
| 82 | + - "{{ docker.dir.config }}/prometheus_pbs_exporter/targets.yml:/config/targets.yml:ro" |
| 83 | + command: "--config.file=/config/targets.yml" |
65 | 84 | restart: true |
66 | 85 | restart_policy: always |
67 | 86 | state: started |
68 | 87 | pull: true |
69 | 88 | labels: |
70 | 89 | traefik.enable: "false" |
71 | 90 | com.unitix.prometheus.pbs-exporter: "true" |
72 | | - loop: "{{ pbs_exporter_instances }}" |
73 | | - loop_control: |
74 | | - label: hidden |
75 | 91 | no_log: true |
0 commit comments