From 3b3dfa2f2e182c8a6485ec2a9b717aa35fa514ad Mon Sep 17 00:00:00 2001 From: Alexander Gorelyshev Date: Sun, 28 Dec 2025 20:04:40 +0400 Subject: [PATCH 1/3] Move the directory creation task outside of block/rescue --- roles/prometheus/tasks/install.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/roles/prometheus/tasks/install.yml b/roles/prometheus/tasks/install.yml index 03877de..f0662b9 100644 --- a/roles/prometheus/tasks/install.yml +++ b/roles/prometheus/tasks/install.yml @@ -7,7 +7,19 @@ create_home: false state: present -- name: "Install | Install the binary" +- name: "Install | Create directories {{ item }}" + loop: + - "{{ prometheus_config_dir }}" + - "{{ prometheus_config_dir }}/rules" + - "{{ prometheus_db_dir }}" + ansible.builtin.file: + path: "{{ item }}" + state: directory + owner: "prometheus" + group: "prometheus" + mode: "0755" + +- name: "Install | Install the binaries" block: - name: "Install | Check Prometheus version" changed_when: false @@ -22,18 +34,6 @@ fail_msg: "prometheus version {{ prometheus_version }} is not installed or not working correctly" rescue: - - name: "Install | Create directories {{ item }}" - with_items: - - "{{ prometheus_config_dir }}" - - "{{ prometheus_config_dir }}/rules" - - "{{ prometheus_db_dir }}" - ansible.builtin.file: - path: "{{ item }}" - state: directory - owner: "prometheus" - group: "prometheus" - mode: "0755" - - name: "Install | Fetch and unpack the distribution" notify: "(Re)start Prometheus service" ansible.builtin.unarchive: From 2cefe656e22c1773bd873d054ebd9ede8d5f45d5 Mon Sep 17 00:00:00 2001 From: Alexander Gorelyshev Date: Sun, 28 Dec 2025 20:04:58 +0400 Subject: [PATCH 2/3] Use the more modern `loop` syntax consistently --- roles/prometheus/tasks/install.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/prometheus/tasks/install.yml b/roles/prometheus/tasks/install.yml index f0662b9..52914c5 100644 --- a/roles/prometheus/tasks/install.yml +++ b/roles/prometheus/tasks/install.yml @@ -43,7 +43,7 @@ remote_src: true - name: "Install | Put the binaries under the PATH" - with_items: + loop: - prometheus - promtool ansible.builtin.copy: From 74a9fb37277f396588060927508243d1ef5dff07 Mon Sep 17 00:00:00 2001 From: Alexander Gorelyshev Date: Sun, 28 Dec 2025 20:05:07 +0400 Subject: [PATCH 3/3] Update `README.md` --- roles/prometheus/README.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/roles/prometheus/README.md b/roles/prometheus/README.md index ba48457..5ffac41 100644 --- a/roles/prometheus/README.md +++ b/roles/prometheus/README.md @@ -17,15 +17,12 @@ Target node: Role Variables -------------- -``` -prometheus_version: 3.2.1 # prometheus version -prometheus_dir: "/etc/prometheus" # where to install prometheus -prometheus_user: prometheus # user name -prometheus_group: prometheus # groups name -prometheus_config_dir: "/etc/prometheus/conf" # where to place prometheus config -prometheus_db_dir: "/var/lib/prometheus" # where to store prometheus db -prometheus_config_source_dir: prometheus # path to config files on source -prometheus_alertrules_source_dir: prometheus/rules # path to rule files on source + +- `prometheus_version`: the desired Prometheus version +- `prometheus_config_source_dir`: where to find config files on the controller +- `prometheus_config_dir`: path for Prometheus configuration file on the target machine +- `prometheus_db_dir`: location for the TSDB files +- `prometheus_alertrules_source_dir`: where to find alert rules on the controller ``` Dependencies