Add the node_exporter role

This commit is contained in:
Alexander Gorelyshev
2025-12-17 12:26:46 +04:00
parent 87cf29448b
commit dce2de2145
12 changed files with 166 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
---
- name: "Install | Check if node_exporter is accessible from $PATH"
changed_when: false
failed_when: false
register: cmd_node_exporter
ansible.builtin.command:
cmd: node_exporter --version
- name: "Install | Build the exporter name"
when: "node_exporter_ver not in cmd_node_exporter.stdout"
ansible.builtin.set_fact:
prom_exp_name: "/node_exporter-{{ node_exporter_ver }}\
.{{ ansible_system | lower }}-\
{{ (ansible_architecture == 'x86_64') | ternary('amd64', ansible_architecture) }}"
- name: "Install | Download the node_exporter binary (release {{ node_exporter_ver }})"
when: "node_exporter_ver not in cmd_node_exporter.stdout"
ansible.builtin.unarchive:
src: "\
https://github.com/prometheus/node_exporter/releases/download/\
v{{ node_exporter_ver }}\
{{ prom_exp_name }}\
.tar.gz"
dest: /tmp
remote_src: true
- name: "Install | Install the downloaded binary to '{{ node_exporter_bin_path }}'"
when: "node_exporter_ver not in cmd_node_exporter.stdout"
changed_when: false
ansible.builtin.command:
cmd: install /tmp/{{ prom_exp_name }}/node_exporter -t {{ node_exporter_bin_path }}
- name: "Install | Push the service file template"
ansible.builtin.template:
src: node_exporter.service.j2
dest: /usr/lib/systemd/system/node_exporter.service
mode: "0660"

View File

@@ -0,0 +1,6 @@
---
- name: "Include installation tasks"
ansible.builtin.include_tasks: "install.yml"
- name: "Including run tasks"
ansible.builtin.include_tasks: "run.yml"

View File

@@ -0,0 +1,8 @@
---
- name: "Enable and start the node_exporter service"
changed_when: false
ansible.builtin.systemd:
name: node_exporter
enabled: true
daemon_reload: true
state: restarted