From be7eca3a8962435cdf478ef889ca2a86947185ce Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 4 Nov 2025 14:18:56 +0100 Subject: [PATCH] prometheus: allow setting custom retention time 15 days is default and also too short. --- roles/prometheus/README.md | 2 +- roles/prometheus/handlers/main.yml | 6 ++++++ roles/prometheus/tasks/main.yml | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/roles/prometheus/README.md b/roles/prometheus/README.md index 13309e1..8764570 100644 --- a/roles/prometheus/README.md +++ b/roles/prometheus/README.md @@ -1,3 +1,3 @@ Install and configure prometheus. -Job definitions should be placed in /etc/prometheus/conf.d by roles using this one. +Job definitions should be placed in /etc/prometheus/conf.d by roles using this one. Data retention time can be set with the `retention` property in a NetBox config context. diff --git a/roles/prometheus/handlers/main.yml b/roles/prometheus/handlers/main.yml index c85cc91..f2d38df 100644 --- a/roles/prometheus/handlers/main.yml +++ b/roles/prometheus/handlers/main.yml @@ -3,3 +3,9 @@ name: prometheus state: reloaded when: "'handler' not in ansible_skip_tags" + +- name: restart prometheus + service: + name: prometheus + state: restarted + when: "'handler' not in ansible_skip_tags" diff --git a/roles/prometheus/tasks/main.yml b/roles/prometheus/tasks/main.yml index 9e44c4d..076f659 100644 --- a/roles/prometheus/tasks/main.yml +++ b/roles/prometheus/tasks/main.yml @@ -8,6 +8,14 @@ path: /etc/prometheus/conf.d state: directory +- name: Configure prometheus retention time + when: retention is defined + lineinfile: + path: /etc/conf.d/prometheus + regexp: "^prometheus_retention_time=" + line: "prometheus_retention_time={{ retention }}" + notify: restart prometheus + - name: Configure prometheus copy: dest: /etc/prometheus/