|
29 | 29 | src: "{{ item.path }}" |
30 | 30 | dest: "{{ prometheus_config_dir }}/rules/{{ item.path | basename }}" |
31 | 31 | mode: 0755 |
| 32 | + validate: "/usr/bin/docker run --rm -v {{ prometheus_config_dir }}:/etc/prometheus --entrypoint '/bin/promtool' {{ prometheus_image }} check rules %s" |
32 | 33 | register: prometheus_alert_confs |
33 | 34 | with_items: "{{ prometheus_alert_rules.files }}" |
34 | 35 | when: |
35 | 36 | - prometheus_alert_rules is defined and prometheus_alert_rules.files | length > 0 |
36 | | - notify: |
37 | | - - Reload prometheus config |
38 | 37 |
|
39 | 38 | - name: Check custom file_sd files exists |
40 | 39 | local_action: |
|
63 | 62 | with_items: "{{ prometheus_file_sd.files }}" |
64 | 63 | when: |
65 | 64 | - prometheus_file_sd is defined and prometheus_file_sd.files | length > 0 |
66 | | - notify: |
67 | | - - Reload prometheus config |
68 | 65 |
|
69 | 66 | - name: Configure Prometheus web |
70 | 67 | ansible.builtin.copy: |
|
118 | 115 | - host_file_sd.files | length > 0 |
119 | 116 |
|
120 | 117 | - name: Validate prometheus config |
121 | | - meta: noop |
122 | | - notify: |
123 | | - - Validate prometheus config |
| 118 | + vars: |
| 119 | + service: "{{ prometheus_services['prometheus'] }}" |
| 120 | + ansible.builtin.shell: | |
| 121 | + /usr/bin/docker run --rm -v {{ prometheus_config_dir }}:/etc/prometheus --entrypoint "/bin/promtool" \ |
| 122 | + {{ prometheus_image }} check config /etc/prometheus/prometheus.yml && \ |
| 123 | + /usr/bin/docker run --rm -v {{ prometheus_config_dir }}:/etc/prometheus --entrypoint "/bin/promtool" \ |
| 124 | + {{ prometheus_image }} check web-config /etc/prometheus/web.yml |
| 125 | + when: |
| 126 | + - inventory_hostname in groups[service.group] |
| 127 | + - service.enabled | bool |
124 | 128 |
|
| 129 | +# NOTE(kiennt26): Reloading the config by sending SIGHUP to the main process, instead of sending a POST request |
| 130 | +# to the /-/reload endpoint, because the latter doesn't work when the basic auth is enabled. |
| 131 | +# The password for the basic auth is encrypted using bcrypt, and I don't want to store the raw password |
| 132 | +# The SIGHUP signal is sent to the process with PID 1 in the container, which is the main process. |
125 | 133 | - name: Reload prometheus config |
126 | | - meta: noop |
127 | | - notify: |
128 | | - - Reload prometheus config |
| 134 | + vars: |
| 135 | + service: "{{ prometheus_services['prometheus'] }}" |
| 136 | + ansible.builtin.command: > |
| 137 | + /usr/bin/docker exec -i {{ prometheus_container_name }} kill -SIGHUP 1 |
| 138 | + register: result |
| 139 | + retries: 5 |
| 140 | + delay: 20 |
| 141 | + until: result.rc == 0 |
| 142 | + when: |
| 143 | + - inventory_hostname in groups[service.group] |
| 144 | + - service.enabled | bool |
129 | 145 |
|
130 | 146 | - name: Check prometheus containers |
131 | 147 | community.general.docker_container: |
|
0 commit comments