Node Exporter Ansible Role¶
An Ansible role to deploy and manage Prometheus Node Exporter using podman-compose.
Features¶
- Deploy Node Exporter as a container using Podman
- Automatic compose stack management
- Easy start/stop/prune operations
- Configurable port and version
- Persistent monitoring with automatic restart
Requirements¶
This role requires the following to be pre-installed on the target system:
podman- Container runtimepodman-compose- Compose tool for Podman
Note: This role does NOT install podman or podman-compose. Please ensure they are installed before using this role.
Installation¶
First add the following line to your requirements.yml file:
roles:
- name: node_exporter
src: https://github.com/niclasheinz/node_exporter.git
version: main
scm: git
After that, we can install the role by executing the following command:
Role Variables¶
Basic Configuration¶
| Variable | Default Value | Type | Description |
|---|---|---|---|
deployment_base_directory |
/opt |
string | Base directory for deployment |
deployment_subdirectory |
node_exporter |
string | Subdirectory name within base directory |
deployment_directory |
{{ deployment_base_directory }}/{{ deployment_subdirectory }} |
string | Full deployment path (auto-constructed) |
deploy_user |
nh |
string | User to run podman-compose commands as |
node_exporter_state |
start |
string | Action to perform: start (deploy), stop (stop stack), or prune (remove all) |
ansible_managed_warning |
"This file is managed by Ansible..." | string | Warning message in managed files |
ansible_role_repository |
https://gitlab.com/niclas-zone/tools/ansible/roles/node_exporter | string | Repository URL |
Note on prune action: The prune state will:
- Stop the compose stack
- Remove the container
- Remove the image locally
- Remove the deployment directory
Node Exporter Configuration¶
| Variable | Default Value | Type | Description |
|---|---|---|---|
node_exporter_version |
v1.9.1 |
string | Docker image version tag for Node Exporter |
node_exporter_image |
docker.io/prom/node-exporter |
string | Docker image to use |
node_exporter_container_name |
node-exporter |
string | Name of the container |
node_exporter_hostname |
{{ inventory_hostname }} |
string | Hostname of the container (defaults to inventory hostname) |
node_exporter_networks |
["monitoring"] |
list | List of networks the container should be connected to |
node_exporter_network_definitions |
See defaults | dict | Network configuration (optional - omit to skip network block) |
node_exporter_volumes |
See defaults | list | Volume mounts for the container |
node_exporter_command_args |
See defaults | list | Command line arguments for node_exporter |
node_exporter_expose_ports |
["9100"] |
list | Ports to expose within the container network |
node_exporter_restart_policy |
unless-stopped |
string | Container restart policy |
node_exporter_logging_driver |
json-file |
string | Logging driver to use |
node_exporter_logging_options |
{"max-size": "10m", "max-file": "3"} |
dict | Logging driver options |
Default volumes:
Default command arguments:
node_exporter_command_args:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- '--path.rootfs=/rootfs'
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($|/)'
- '--web.listen-address=:9100'
Default network definitions:
Note: The networks: block in the compose file will only be generated if node_exporter_network_definitions is defined and not empty. To omit the network definitions block entirely, set node_exporter_network_definitions: {}.
Example Playbooks¶
Basic Deployment¶
Custom Configuration¶
---
- hosts: servers
become: true
roles:
- role: node_exporter
vars:
deployment_base_directory: "/opt"
deploy_user: "monitoring"
node_exporter_version: "v1.7.0"
External Networks¶
---
- hosts: servers
become: true
roles:
- role: node_exporter
vars:
node_exporter_networks:
- monitoring
- backend
node_exporter_network_definitions:
monitoring:
external:
name: monitoring
backend:
external:
name: backend