ansible/roles/prometheus-node-exporter/tasks/main.yml

84 lines
2.1 KiB
YAML

---
- name: Install Prometheus Node exporter
apt:
name:
- prometheus-node-exporter
state: latest
update_cache: true
install_recommends: false # Do not install smartmontools
register: apt_result
retries: 3
until: apt_result is succeeded
- name: Ensure /etc/node_exporter exist
file:
path: /etc/node_exporter
state: directory
group: prometheus
owner: prometheus
mode: u=rwx,g=rx,o=rx
- name: Copy the config folder
template:
src: config.yaml
dest: /etc/node_exporter/config.yaml
group: prometheus
owner: prometheus
mode: u=rw,g=r,o=r
notify: Restart prometheus-node-exporter
- name: Generate certificate
include_role:
name: generate-cert
vars:
directory: /etc/node_exporter/
cname: "node-exp-{{ lan_address }}"
owner: prometheus
group: prometheus
key_mode: u=rw,g=,o=
subject_alt_name: "IP:{{ lan_address }}"
# Need an equivalent to notify here
- name: Copy the CA cert
copy:
content: "{{ ca_cert }}"
dest: /etc/node_exporter/ca.crt
notify: Restart prometheus-node-exporter
- name: Setup the arguments for node-exporter
template:
src: prometheus-node-exporter
dest: /etc/default/prometheus-node-exporter
owner: root
group: root
mode: u=rw,g=r,o=r
notify: Restart prometheus-node-exporter
vars:
args:
- name: web.listen-address
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 }}"