|
1 | 1 | --- |
2 | | -- name: Validate PBS exporter credentials |
| 2 | +- name: Validate PBS exporter instances list |
3 | 3 | ansible.builtin.assert: |
4 | 4 | that: |
5 | | - - pbs_exporter_api_token_id is defined |
6 | | - - pbs_exporter_api_token_id | length > 0 |
7 | | - - pbs_exporter_api_token_secret is defined |
8 | | - - pbs_exporter_api_token_secret | length > 0 |
| 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 | 9 | fail_msg: >- |
10 | | - pbs_exporter_api_token_id and pbs_exporter_api_token_secret must be |
11 | | - supplied as inventory variables. |
| 10 | + pbs_exporter_instances must be a non-empty inventory list. |
12 | 11 | no_log: true |
13 | 12 |
|
14 | | -- name: Setup Prometheus PBS exporter |
| 13 | +- name: Validate PBS exporter instances |
| 14 | + ansible.builtin.assert: |
| 15 | + that: |
| 16 | + - item.name is defined |
| 17 | + - item.name is string |
| 18 | + - item.name is match('^[a-z0-9][a-z0-9-]*$') |
| 19 | + - item.netbox_name is defined |
| 20 | + - item.netbox_name is string |
| 21 | + - item.netbox_name | length > 0 |
| 22 | + - item.api_token_id is defined |
| 23 | + - item.api_token_id is string |
| 24 | + - item.api_token_id | length > 0 |
| 25 | + - item.api_token_secret is defined |
| 26 | + - item.api_token_secret is string |
| 27 | + - item.api_token_secret | length > 0 |
| 28 | + 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 }}" |
| 32 | + loop_control: |
| 33 | + label: hidden |
| 34 | + no_log: true |
| 35 | + |
| 36 | +- name: Validate unique PBS exporter instance selectors |
| 37 | + ansible.builtin.assert: |
| 38 | + that: |
| 39 | + - >- |
| 40 | + pbs_exporter_instances | map(attribute='name') | unique | list | length |
| 41 | + == pbs_exporter_instances | length |
| 42 | + - >- |
| 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. |
| 46 | + no_log: true |
| 47 | + |
| 48 | +- name: Remove legacy Prometheus PBS exporter |
15 | 49 | community.docker.docker_container: |
16 | 50 | name: prometheus-pbs_exporter |
| 51 | + state: absent |
| 52 | + no_log: true |
| 53 | + |
| 54 | +- name: Setup Prometheus PBS exporters |
| 55 | + community.docker.docker_container: |
| 56 | + name: "prometheus-pbs-exporter-{{ item.name }}" |
17 | 57 | image: "{{ pbs_exporter_image | default('natrontech/pbs-exporter:latest') }}" |
18 | 58 | networks: |
19 | 59 | - name: monitoring |
20 | 60 | dns_servers: "{{ dns.servers }}" |
21 | 61 | env: |
22 | | - PBS_TOKEN_ID: "{{ pbs_exporter_api_token_id }}" |
23 | | - PBS_TOKEN_SECRET: "{{ pbs_exporter_api_token_secret }}" |
| 62 | + PBS_TOKEN_ID: "{{ item.api_token_id }}" |
| 63 | + PBS_TOKEN_SECRET: "{{ item.api_token_secret }}" |
24 | 64 | PBS_TLS_INSECURE: "true" |
25 | 65 | restart: true |
26 | 66 | restart_policy: always |
27 | 67 | state: started |
28 | 68 | pull: true |
29 | 69 | labels: |
30 | 70 | traefik.enable: "false" |
| 71 | + com.unitix.prometheus.pbs-exporter: "true" |
| 72 | + loop: "{{ pbs_exporter_instances }}" |
| 73 | + loop_control: |
| 74 | + label: hidden |
31 | 75 | no_log: true |
0 commit comments