Merge pull request #36 from corvus-migratorius/role-node-exporter

Add the `node_exporter` role
This commit is contained in:
Alexander Gorelyshev
2025-12-17 13:51:32 +04:00
committed by GitHub
12 changed files with 167 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
Role Name
=========
Deploy `prometheus/node_exporter` binary as a systemd unit.
Requirements
------------
None
Role Variables
--------------
`node_exporter_bin_path`: where to install the binary (default: `/usr/bin`).
Dependencies
------------
None
Example Playbook
----------------
See: [converge.yml](molecule/default/converge.yml)
License
-------
BSD
Author Information
------------------
corvus-migratorius@proton.me

View File

@@ -0,0 +1,2 @@
---
node_exporter_bin_path: /usr/bin

View File

@@ -0,0 +1 @@
---

View File

@@ -0,0 +1,17 @@
---
galaxy_info:
role_name: node_exporter
namespace: genlab
author: "Alexander Gorelyshev"
company: "Genlab, LLC"
description: "Deploy prometheus/node_exporter binary as a systemd unit"
license: "GPL-2.0-or-later"
min_ansible_version: "2.1"
platforms:
- name: "Ubuntu"
versions: ["focal", "jammy"]
galaxy_tags: ["prometheus"]
dependencies: []

View File

@@ -0,0 +1,6 @@
---
- name: Converge
hosts: all
roles:
- role: genlab.common.node_exporter
node_exporter_ver: "1.10.1"

View File

@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ubuntu
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
provisioner:
name: ansible
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint .

View File

@@ -0,0 +1,16 @@
# kics-scan disable=2e8d4922-8362-4606-8c14-aa10466a1ce3
---
- name: Verify
hosts: all
gather_facts: false
any_errors_fatal: true
tasks:
- name: "Sanity check the node exporter"
retries: 5
delay: 1
register: node_exporter_check
failed_when: '"node_exporter_build_info" not in node_exporter_check.content'
ansible.builtin.uri:
url: "http://localhost:9100/metrics"
return_content: true

View File

@@ -0,0 +1,37 @@
---
- name: "Install | Check if node_exporter is accessible from $PATH"
changed_when: false
failed_when: false
register: node_exporter_cmd
ansible.builtin.command:
cmd: node_exporter --version
- name: "Install | Build the exporter name"
when: "node_exporter_ver not in node_exporter_cmd.stdout"
ansible.builtin.set_fact:
node_exporter_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 node_exporter_cmd.stdout"
ansible.builtin.unarchive:
src: "\
https://github.com/prometheus/node_exporter/releases/download/\
v{{ node_exporter_ver }}\
{{ node_exporter_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 node_exporter_cmd.stdout"
changed_when: false
ansible.builtin.command:
cmd: install /tmp/{{ node_exporter_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

View File

@@ -0,0 +1,12 @@
[Unit]
Description=Node Exporter
After=network.target
[Service]
Type=simple
ExecStart={{ node_exporter_bin_path }}/node_exporter \
--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/) \
--collector.systemd
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1 @@
---