summaryrefslogtreecommitdiffstats
path: root/roles/prometheus/tasks
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2025-09-15 22:17:49 +0200
committerAhmed Abdelhalim <[email protected]>2025-09-15 22:26:15 +0200
commitd7c3044edf15ca2ee8a8bcc2fcdce8e26e4133d9 (patch)
tree111df0a6afbf307b6ed9e7a112d02dffa506e892 /roles/prometheus/tasks
parent42899d44598c9cd848af1c86427f0b4c03f54493 (diff)
Add prometheus role (with node exporter)
Diffstat (limited to 'roles/prometheus/tasks')
-rw-r--r--roles/prometheus/tasks/main.yml55
1 files changed, 55 insertions, 0 deletions
diff --git a/roles/prometheus/tasks/main.yml b/roles/prometheus/tasks/main.yml
new file mode 100644
index 00000000..9feeacaf
--- /dev/null
+++ b/roles/prometheus/tasks/main.yml
@@ -0,0 +1,55 @@
+---
+- name: "Create prometheus group"
+ become: true
+ ansible.builtin.group:
+ name: "prometheus"
+ system: true
+
+- name: "Create prometheus user"
+ become: true
+ ansible.builtin.user:
+ name: "prometheus"
+ group: "prometheus"
+ system: true
+ shell: "/usr/sbin/nologin"
+ create_home: false
+
+- name: "Create prometheus directories"
+ become: true
+ ansible.builtin.file:
+ path: "{{ item }}"
+ state: "directory"
+ owner: "prometheus"
+ group: "prometheus"
+ mode: "0755"
+ with_items:
+ - "/etc/prometheus"
+ - "/var/lib/prometheus"
+
+- name: "Install prometheus packages"
+ become: true
+ ansible.builtin.package:
+ name:
+ - "prometheus"
+ - "prometheus-node-exporter"
+ state: "present"
+
+- name: "Create prometheus configuration"
+ become: true
+ ansible.builtin.template:
+ src: "prometheus.yml.j2"
+ dest: "/etc/prometheus/prometheus.yml"
+ owner: "prometheus"
+ group: "prometheus"
+ mode: "0644"
+ notify: "Restart prometheus"
+
+- name: "Start and enable prometheus services"
+ become: true
+ ansible.builtin.systemd_service:
+ name: "prometheus"
+ state: "started"
+ enabled: true
+ with_items:
+ - "prometheus"
+ - "prometheus-node-exporter"