register nodes on the server

This commit is contained in:
histausse 2021-09-21 14:53:25 +02:00
parent 3d094d13eb
commit 586244a98f
Signed by: histausse
GPG key ID: 67486F107F62E9E9
4 changed files with 30 additions and 2 deletions

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ansible-playbook
---
- hosts: prometheus_server
- hosts: prometheus_servers
roles:
- prometheus

View file

@ -2,3 +2,6 @@
# Use python 3
ansible_python_interpreter: /usr/bin/python3
dns_resolve_server: 1.1.1.1
# Default prometheus serveur, to overide in host_vars or something
appointed_prometheus_server: hindley

4
hosts
View file

@ -30,6 +30,8 @@ all:
tests:
hosts:
rossum:
azerty:
hellman:
vpn:
hosts:
azerty:
@ -40,7 +42,7 @@ all:
apt_proxies:
hosts:
hindley:
prometheus_server:
prometheus_servers:
hosts:
hindley:
matrix:

View file

@ -30,3 +30,26 @@
value: "{{ lan_address }}:9100"
# - name: web.config
# value: /etc/node_exporter/config.yaml
# Add the node to the server targets
- name: Get the list of targets of the server
slurp:
src: /etc/prometheus/node-targets.json
register: server_target_file
delegate_to: "{{ appointed_prometheus_server }}"
- name: Set target variable
set_fact:
server_target: "{{ server_target_file['content'] | b64decode | from_json }}"
- name: Add the node to the targets
set_fact:
server_target: "[{{ server_target[0] | combine({'targets': [lan_address]}, list_merge='append_rp') }}]"
- name: Put the new target list
copy:
content: "{{ server_target | to_nice_json }}"
dest: /etc/prometheus/node-targets.json
delegate_to: "{{ appointed_prometheus_server }}"