Ansible Role - Node Exporter
MIT License
Node Exporter role is designed to simplify the installation and configuration of Node Exporter on various Linux distributions. Node Exporter is a popular Prometheus exporter that collects hardware and operating system metrics from Linux systems.
This role provides a straightforward way to deploy Node Exporter across systems from the Red Hat Enterprise Linux (RHEL) family, including RHEL 8
, RHEL 9
, Rocky Linux
, Alma Linux
, CentOS
, and Fedora
. It has been tested extensively on RHEL 8
and RHEL 9
, ensuring compatibility and reliability.
Role support two scenarios:
present
). It installs and configures Node Exporter on the target system.uninstall
). It removes Node Exporter from the target system.Role Key feature:
π’ Check the blog post π Experience a step-by-step demo of deploying and uninstalling Node Exporter using my Ansible role.
No requirements
host_vars
or group_vars
if required.Variable Name | Default Value | Description |
---|---|---|
node_exporter_version |
"latest" |
The version of Node Exporter to download and deploy. Supported standard version "1.6.0" format or "latest". |
node_exporter_binary_path |
/usr/local/bin |
The path where the Node Exporter binary is located. |
node_exporter_user |
"node_exporter" |
The user under which the Node Exporter service runs. This user is marked as a system user. |
node_exporter_group |
"node_exporter" |
The system group associated with the Node Exporter service. |
node_exporter_web_listen_address |
"0.0.0.0" |
The address on which Node Exporter listens for HTTP requests. By default, it listens on all interfaces. |
node_exporter_listen_port |
9100 |
The TCP port on which Node Exporter listens for incoming connections. By default, it listens on port 9100 . |
node_exporter_expose_port |
true |
Set to true by default, controls whether to add a firewalld rule for exposing the Node Exporter port. When true , a firewalld rule is added to allow inbound traffic on the specified Node Exporter port. Set to false to ensure that firewalld rule is not present. |
node_exporter_arch |
"amd64" |
The architecture of the Linux system for which Node Exporter is being deployed. |
node_exporter_download_url |
https://github.com/ prometheus/ node_exporter/releases/ download/ v{{ node_exporter_version }} /node_exporter- {{ node_exporter_version }} .linux- {{ node_exporter_arch }}.tar.gz
|
The default download URL for the Node Exporter package from GitHub. |
Variable Name | Example Usage | Required | Description |
---|---|---|---|
node_exporter_runtime_flags |
node_exporter_runtime_flags:β- "--collector.textfile.directory {{ node_exporter_textfile_path }}"β- "--collector.systemd"β- "--collector.network_route" | No | Optional execution flags injected into the systemd unit file for Node Exporter. You can refer to the official node exporter Github repo to obtain a list of available collectors. |
node_exporter_textfile_path |
"/var/lib/node_exporter" |
NO(required when runtime flag textfile is defined) | If you define the --collector.textfile.directory flag in the node_exporter_runtime_flags variable, it is required to specify the directory path. By default, the directory is not created. The textfile collector serves a specific purpose as explained in the provided link. |
No Dependencies
function_node-exporter_deploy.yml
)- name: Deploy node_exporter service
hosts: node_exporter
gather_facts: false
become: true
roles:
- role: voidquark.node_exporter
state: present
function_node-exporter_uninstall.yml
)- name: Uninstall node_exporter service
hosts: node_exporter
gather_facts: false
become: true
roles:
- role: voidquark.node_exporter
state: absent
ansible-playbook -i inventory/hosts function_node-exporter_deploy.yml
ansible-playbook -i inventory/hosts function_node-exporter_uninstall.yml --limit "node2.voidquark.com"
Here is an example of how you can organize your files using a directory structure for your Ansible project. This structure demonstrates where to place the playbook (deploy/uninstall), the inventory file, and where to include this role.
ansible_structure
βββ automation
βΒ Β βββ function_node-exporter_deploy.yml # Deployment playbook
βΒ Β βββ function_node-exporter_uninstall.yml # Uninstall playbook
βββ inventory
βββ group_vars
βΒ Β βββ node_exporter
βΒ Β βββ node_exporter_vars.yml # Overwrite variables in group_vars (optional)
βββ hosts
βββ host_vars
βββ node1.voidquark.com
βΒ Β βββ host_vars.yml # Overwrite variables in host_vars (optional)
βββ node2.voidquark.com
βββ host_vars.yml # Overwrite variables in host_vars (optional)
hosts
file example:[node_exporter]
node1.voidquark.com
node2.voidquark.com
MIT
Feel free to customize and enhance the role according to your needs. Your feedback and contributions are greatly appreciated. Please open an issue or submit a pull request with any improvements.
Created by VoidQuark