This Ansible role installs and configures Prometheus from the official GitHub release.
It also supports provisioning targets for Node Exporter.
The role performs the following tasks:
- Checks whether Prometheus is already installed
- Installs Prometheus if it is not present
- Creates a dedicated
prometheussystem user - Creates required directories
- Downloads and installs Prometheus binaries
- Deploys Prometheus configuration
- Creates and enables a systemd service
- Optionally provisions Node Exporter targets
- Ansible >= 2.9
- Linux system with systemd
- Internet access to download Prometheus releases
Variables are defined in defaults/main.yml.
| Variable | Default | Description |
|---|---|---|
| prometheus_version | 3.9.1 |
Prometheus version to install |
| provision | node_exporter |
Enables Node Exporter provisioning |
Example override:
prometheus_version: 3.9.1
provision: node_exporteransible-role-prometheus
├── defaults
│ └── main.yml
├── files
│ └── config.yml
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── tasks
│ ├── install.yml
│ ├── main.yml
│ └── provision_node_exporter.yml
├── templates
│ ├── node_exporter_targets.json.j2
│ ├── prometheus.service.j2
│ └── prometheus.yml.j2
├── tests
│ ├── ansible.cfg
│ ├── inventory.yml
│ └── test.yml
├── vars
│ └── main.yml
└── README.md
- Checks whether Prometheus is installed:
which prometheus
- If Prometheus is not installed:
- Creates the
prometheususer - Creates required directories:
/etc/prometheus
/var/lib/prometheus
-
Downloads Prometheus from GitHub releases.
-
Extracts the archive and installs binaries:
/usr/local/bin/prometheus
/usr/local/bin/promtool
- Deploys the Prometheus configuration file:
/etc/prometheus/prometheus.yml
- Installs the systemd service:
/etc/systemd/system/prometheus.service
- Enables and starts Prometheus.
- hosts: prometheus
become: true
roles:
- prometheusall:
hosts:
prometheus:
ansible_host: 192.168.1.10After installation, Prometheus will be available at:
http://<server_ip>:9090
Check service status:
systemctl status prometheus
This role supports automatic provisioning of Node Exporter targets using file-based service discovery.
Targets are generated from the template:
templates/node_exporter_targets.json.j2
A simple test environment is available in the tests directory.
Run the test playbook:
ansible-playbook -i tests/inventory.yml tests/test.yml
MIT