2021-09-05 22:35:10 +02:00
|
|
|
---
|
|
|
|
- name: Install Prometheus Node exporter
|
|
|
|
apt:
|
|
|
|
name:
|
|
|
|
- prometheus-node-exporter
|
|
|
|
state: latest
|
|
|
|
update_cache: true
|
2021-09-06 01:18:10 +02:00
|
|
|
install_recommends: false # Do not install smartmontools
|
2021-09-05 22:35:10 +02:00
|
|
|
register: apt_result
|
|
|
|
retries: 3
|
|
|
|
until: apt_result is succeeded
|
|
|
|
|
|
|
|
# TODO: add auth
|
|
|
|
#
|
|
|
|
# Create the file --web.config=/etc/node_exporter/config.yaml
|
|
|
|
# and add --web.config=/etc/node_exporter/config.yaml to
|
|
|
|
# the args in /etc/default/prometheus-node-exporter
|
2021-09-06 00:24:56 +02:00
|
|
|
|
|
|
|
- name: Setup the arguments for node-exporter
|
|
|
|
template:
|
|
|
|
src: prometheus-node-exporter
|
|
|
|
dest: /etc/default/prometheus-node-exporter
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
|
|
|
notify: Restart prometheus-node-exporter
|
|
|
|
vars:
|
|
|
|
args:
|
|
|
|
- name: web.listen-address
|
|
|
|
value: "{{ lan_address }}:9100"
|
|
|
|
# - name: web.config
|
|
|
|
# value: /etc/node_exporter/config.yaml
|
2021-09-21 14:53:25 +02:00
|
|
|
|
|
|
|
# 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 }}"
|
|
|
|
|