Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
deb528a
Add role for pve_exporter
juju4 Jan 19, 2025
8bacbc0
ci: fix arguments-spec-lint
juju4 Jan 19, 2025
3257545
ci: fix check-unused-variables
juju4 Jan 19, 2025
eb9a8f4
fix: remove invalid debug option
juju4 Jan 19, 2025
2b84d50
ci: add test/integration/targets
juju4 Jan 19, 2025
186e5a3
feat: option to set up exporter credentials in proxmox if local
juju4 Jan 25, 2025
3d614da
chore: fix ansible-lint
juju4 Jan 25, 2025
0f36cad
fix: missing condition
juju4 Feb 16, 2025
88b8c8f
Merge branch 'main' into devel-pve
juju4 Feb 16, 2025
a207551
style: use ansible_facts python and venv module
juju4 Feb 22, 2025
8a769c0
style: ansible_facts python and venv module install
juju4 Feb 22, 2025
8dc6667
style: split install tasks
juju4 Feb 22, 2025
42a1b68
fix: missing closing quotes
juju4 Feb 22, 2025
bb4a9f5
Merge branch 'main' into devel-pve
juju4 Feb 23, 2025
13cdda5
fix: s/ansible_python/python/
juju4 Mar 2, 2025
87e3988
Merge branch 'main' into devel-pve
juju4 Apr 6, 2025
ece8793
feat: Add role for pve_exporter
juju4 Apr 19, 2025
74797c1
Merge branch 'devel-pve' of github.com:juju4/ansible-prometheus-colle…
juju4 Apr 19, 2025
4d53ac7
Merge branch 'main' into devel-pve
juju4 Jun 14, 2025
baa0b0a
fix(redhat): add epel role for almalinux integration tests
juju4 Jun 14, 2025
c239497
fix(redhat): add epel role for almalinux integration tests - requirem…
juju4 Jun 14, 2025
0d3e32a
Revert "fix(redhat): add epel role for almalinux integration tests - …
juju4 Jun 14, 2025
5e6be66
Revert "fix(redhat): add epel role for almalinux integration tests"
juju4 Jun 14, 2025
6b957bf
fix(redhat): add epel for almalinux inline
juju4 Jun 14, 2025
54dfdf1
fix: ansible variables under ansible_facts
juju4 Jun 14, 2025
ea7545b
fix: ansible variables under ansible_facts (2)
juju4 Jun 14, 2025
2e20da2
fix(redhat): remove crb on redhat-9
juju4 Jun 14, 2025
7726b2c
fix(redhat): switch from venv to virtualenv
juju4 Jun 14, 2025
bf63ec5
Merge branch 'main' into devel-pve
juju4 Aug 30, 2025
e1a09c6
fix: INJECT_FACTS_AS_VARS - porting ansible 13
juju4 Feb 7, 2026
0555d94
Merge branch 'main' into devel-pve
juju4 Feb 7, 2026
e300fb5
Merge branch 'main' into devel-pve
SuperQ Mar 6, 2026
2bd9a31
Merge branch 'main' into devel-pve
juju4 Mar 7, 2026
2179204
fix(redhat): add CRB repo, broken conditionals
juju4 Mar 7, 2026
e7fefdc
Merge branch 'devel-pve' of github.com:juju4/ansible-prometheus-colle…
juju4 Mar 7, 2026
650f815
fix: redhatepel_crb_file vars
juju4 Mar 7, 2026
7253c29
fix(almalinux-9): redhatepel_crb_file vars
juju4 Mar 7, 2026
07d07f4
fix: pip install without become - user shell issue?
juju4 Mar 8, 2026
184f06f
Merge branch 'main' into devel-pve
juju4 Apr 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions roles/pve_exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Ansible Role: pve exporter

## Description

Deploy prometheus [pve exporter](https://github.com/prometheus-pve/prometheus-pve-exporter), written in python, using ansible.

Possible Grafana dashboard: https://grafana.com/grafana/dashboards/10347-proxmox-via-prometheus/

## Requirements

- Ansible >= 2.9 (It might work on previous versions, but we cannot guarantee it)

## Role Variables

All variables which can be overridden are stored in [defaults/main.yml](defaults/main.yml) file as well as in [meta/argument_specs.yml](meta/argument_specs.yml).
Please refer to the [collection docs](https://prometheus-community.github.io/ansible/branch/main/pve_exporter_role.html) for description and default values of the variables.

## Example

### Playbook

Use it in a playbook as follows:
```yaml
- hosts: all
roles:
- prometheus.prometheus.pve_exporter
```

## Local Testing

The preferred way of locally testing the role is to use Docker and [molecule](https://github.com/ansible-community/molecule) (v3.x). You will have to install Docker on your system. See "Get started" for a Docker package suitable for your system. Running your tests is as simple as executing `molecule test`.

## Continuous Integration

Combining molecule and circle CI allows us to test how new PRs will behave when used with multiple ansible versions and multiple operating systems. This also allows use to create test scenarios for different role configurations. As a result we have quite a large test matrix which can take more time than local testing, so please be patient.

## Contributing

See [contributor guideline](CONTRIBUTING.md).

## Troubleshooting

See [troubleshooting](TROUBLESHOOTING.md).

## License

This project is licensed under MIT License. See [LICENSE](/LICENSE) for more details.
1 change: 1 addition & 0 deletions roles/pve_exporter/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Troubleshooting
35 changes: 35 additions & 0 deletions roles/pve_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
pve_exporter_version: 3.5.0
# not go, but python pip. placeholders for _common
pve_exporter_textfile_dir: ""
pve_exporter_tls_server_config: {}
pve_exporter_http_server_config: {}
pve_exporter_basic_auth_users: {}
# just for "prometheus.prometheus._common : Naive assertion of proper listen address" else not used
pve_exporter_web_listen_address: "127.0.0.1:9221"

# cluster collectors
pve_exporter_enabled_collectors: []
# pve_exporter_enabled_collectors:
# - status
# - version
# - node
# - cluster
# - resources
pve_exporter_disabled_collectors: []

pve_exporter_home: "/var/lib/pve_exporter"
pve_exporter_virtualenv: "/var/lib/pve_exporter/venv"

pve_exporter_auth_user: prometheus@pve
pve_exporter_auth_pass:
pve_exporter_auth_verify_ssl: true
pve_exporter_auth_token_name: your-token-id
pve_exporter_auth_token_value:

pve_exporter_config_template: pve_exporter.yml.j2

pve_exporter_system_group: "pve-exp"
pve_exporter_system_user: "{{ pve_exporter_system_group }}"

pve_exporter_config_dir: "/etc/pve_exporter"
10 changes: 10 additions & 0 deletions roles/pve_exporter/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Restart pve_exporter
listen: "restart pve_exporter"
become: true
ansible.builtin.systemd:
daemon_reload: true
name: pve_exporter
state: restarted
when:
- not ansible_check_mode
86 changes: 86 additions & 0 deletions roles/pve_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
# yamllint disable rule:line-length
argument_specs:
main:
short_description: "Prometheus Proxmox VE Exporter"
description:
- "Deploy prometheus L(pve exporter,https://github.com/prometheus-pve/prometheus-pve-exporter) using ansible"
author:
- "Prometheus Community"
options:
pve_exporter_home:
description: "Home of pve_exporter user and base file locations"
default: "/var/lib/pve_exporter"
pve_exporter_virtualenv:
description: "Python virtualenv filepath for pve_exporter"
default: "/var/lib/pve_exporter/venv"
pve_exporter_auth_user:
description: "Authentication PVE user name if using user/password auth"
default: "prometheus@pve"
pve_exporter_auth_pass:
description: "Authentication PVE user password if using user/password auth"
pve_exporter_auth_verify_ssl:
description: "Validate proxmox certificate or not"
type: bool
default: true
pve_exporter_auth_token_name:
description: "Authentication PVE user token name if using token auth"
default: your-token-id
pve_exporter_auth_token_value:
description: "Authentication PVE user token value from `pveum user token add ...`"
pve_exporter_config_template:
description: "Configuration template for pve_exporter"
default: "pve_exporter.yml.j2"
pve_exporter_version:
description: "Proxmox VE Exporter package version. Also accepts latest as parameter."
default: "1.0.0"
pve_exporter_web_listen_address:
description: "Address on which pve exporter will listen"
default: "0.0.0.0:15353"
pve_exporter_enabled_collectors:
description:
- "List of dicts defining additionally enabled collectors and their configuration."
- "It adds collectors to L(those enabled by default,https://github.com/prometheus-pve/prometheus-pve-exporter#enabled-by-default)."
type: "list"
default:
- systemd
- textfile:
directory: "{{ pve_exporter_textfile_dir }}"
pve_exporter_disabled_collectors:
description:
- "List of disabled collectors."
- "By default pve_exporter disables collectors listed L(here,https://github.com/prometheus-pve/prometheus-pve-exporter#disabled-by-default)."
type: "list"
elements: "str"
pve_exporter_textfile_dir:
description:
- "Directory used by the L(Textfile Collector,https://github.com/prometheus-pve/prometheus-pve-exporter#textfile-collector)."
- "To get permissions to write metrics in this directory, users must be in C(pve-exp) system group."
- "B(Note:) More information in TROUBLESHOOTING.md guide."
default: "/var/lib/pve_exporter"
pve_exporter_tls_server_config:
description:
- "Configuration for TLS authentication."
- "Keys and values are the same as in L(pve_exporter docs,https://prometheus.io/docs/prometheus/latest/configuration/https/)."
type: "dict"
pve_exporter_http_server_config:
description:
- "Config for HTTP/2 support."
- "Keys and values are the same as in L(pve_exporter docs,https://prometheus.io/docs/prometheus/latest/configuration/https/)."
type: "dict"
pve_exporter_basic_auth_users:
description: "Dictionary of users and password for basic authentication. Passwords are automatically hashed with bcrypt."
type: "dict"
pve_exporter_system_group:
description:
- "I(Advanced)"
- "System group for pve exporter"
default: "pve-exp"
pve_exporter_system_user:
description:
- "I(Advanced)"
- "Proxmox VE Exporter user"
default: "pve-exp"
pve_exporter_config_dir:
description: "Path to directory with pve_exporter configuration"
default: "/etc/pve_exporter"
25 changes: 25 additions & 0 deletions roles/pve_exporter/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
galaxy_info:
author: "Prometheus Community"
description: "Prometheus Proxmox VE Exporter"
license: "Apache"
min_ansible_version: "2.9"
platforms:
- name: "Ubuntu"
versions:
- "focal"
- "jammy"
- "noble"
- name: "Debian"
versions:
- "bullseye"
- name: "EL"
versions:
- "8"
- "9"
galaxy_tags:
- "monitoring"
- "prometheus"
- "exporter"
- "metrics"
- "system"
23 changes: 23 additions & 0 deletions roles/pve_exporter/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
provisioner:
playbooks:
prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml"
inventory:
group_vars:
all:
pve_exporter_web_listen_address:
- '127.0.0.1:8080'
- '127.0.1.1:8080'
pve_exporter_textfile_dir: ""
pve_exporter_enabled_collectors:
- entropy
pve_exporter_disabled_collectors:
- diskstats
pve_exporter_tls_server_config:
cert_file: /etc/pve_exporter/tls.cert
key_file: /etc/pve_exporter/tls.key
pve_exporter_http_server_config:
http2: true
pve_exporter_basic_auth_users:
randomuser: examplepassword
pve_exporter_version: 3.5.0
43 changes: 43 additions & 0 deletions roles/pve_exporter/molecule/alternative/tests/test_alternative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from testinfra_helpers import get_target_hosts
import pytest

testinfra_hosts = get_target_hosts()


def test_directories(host):
dirs = [
"/var/lib/pve_exporter"
]
for dir in dirs:
d = host.file(dir)
assert not d.exists


def test_service(host):
s = host.service("pve_exporter")
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u pve_exporter --since "1 hour ago"')
print("\n==== journalctl -u pve_exporter Output ====\n")
print(journal_output)
print("\n============================================\n")
raise # Re-raise the original assertion error


def test_protecthome_property(host):
s = host.service("pve_exporter")
p = s.systemd_properties
assert p.get("ProtectHome") == "yes"


@pytest.mark.parametrize("sockets", [
"tcp://127.0.0.1:8080",
"tcp://127.0.1.1:8080",
])
def test_socket(host, sockets):
assert host.socket(sockets).is_listening
6 changes: 6 additions & 0 deletions roles/pve_exporter/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
provisioner:
inventory:
group_vars:
all:
pve_exporter_web_listen_address: "127.0.0.1:9221"
76 changes: 76 additions & 0 deletions roles/pve_exporter/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from testinfra_helpers import get_target_hosts

testinfra_hosts = get_target_hosts()


def test_directories(host):
dirs = [
"/var/lib/pve_exporter"
]
for dir in dirs:
d = host.file(dir)
assert d.is_directory
assert d.exists


def test_files(host):
files = [
"/etc/systemd/system/pve_exporter.service",
"/usr/local/bin/pve_exporter"
]
for file in files:
f = host.file(file)
assert f.exists
assert f.is_file


def test_permissions_didnt_change(host):
dirs = [
"/etc",
"/root",
"/usr",
"/var"
]
for file in dirs:
f = host.file(file)
assert f.exists
assert f.is_directory
assert f.user == "root"
assert f.group == "root"


def test_user(host):
assert host.group("pve-exp").exists
assert "pve-exp" in host.user("pve-exp").groups
assert host.user("pve-exp").shell == "/usr/sbin/nologin"


def test_service(host):
s = host.service("pve_exporter")
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u pve_exporter --since "1 hour ago"')
print("\n==== journalctl -u pve_exporter Output ====\n")
print(journal_output)
print("\n============================================\n")
raise # Re-raise the original assertion error


def test_protecthome_property(host):
s = host.service("pve_exporter")
p = s.systemd_properties
assert p.get("ProtectHome") == "yes"


def test_socket(host):
sockets = [
"tcp://127.0.0.1:9221"
]
for socket in sockets:
s = host.socket(socket)
assert s.is_listening
7 changes: 7 additions & 0 deletions roles/pve_exporter/molecule/latest/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
provisioner:
inventory:
group_vars:
all:
pve_exporter_version: latest
pve_exporter_textfile_dir: /home/pve_exporter
Loading