register nodes on the server
This commit is contained in:
parent
3d094d13eb
commit
586244a98f
4 changed files with 30 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env ansible-playbook
|
||||
---
|
||||
- hosts: prometheus_server
|
||||
- hosts: prometheus_servers
|
||||
roles:
|
||||
- prometheus
|
||||
|
||||
|
|
|
@ -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
4
hosts
|
@ -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:
|
||||
|
|
|
@ -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 }}"
|
||||
|
||||
|
|
Loading…
Reference in a new issue