2025-02-06 02:20:33 +10:00

133 lines
3.6 KiB
YAML

---
- name: prom
hosts:
- prometheus.guaranteedstruggle.host
vars:
prom_version: '2.55.1'
gather_facts: yes
become: yes
tasks:
- name: Ensure group "prometheus" exists
ansible.builtin.group:
name: prometheus
state: present
- name: Add user "prometheus"
ansible.builtin.user:
name: prometheus
groups: prometheus
shell: /sbin/nologin
create_home: no
append: yes
comment: "prometheus nologin User"
state: present
- name: Creates directory
ansible.builtin.file:
path: /etc/prometheus
state: directory
group: prometheus
owner: prometheus
- name: Creates directory
ansible.builtin.file:
path: /usr/share/prometheus
state: directory
group: prometheus
owner: prometheus
- name: Creates directory
ansible.builtin.file:
path: /prometheus-data
state: directory
group: prometheus
owner: prometheus
- name: Unarchive a file that needs to be downloaded (added in 2.0)
ansible.builtin.unarchive:
src: https://github.com/prometheus/prometheus/releases/download/v{{prom_version}}/prometheus-{{prom_version}}.linux-amd64.tar.gz
dest: /usr/share/prometheus
creates: /usr/share/prometheus/prometheus-{{prom_version}}.linux-amd64
remote_src: yes
- name: Create a symbolic link
ansible.builtin.file:
src: /usr/share/prometheus/prometheus-{{prom_version}}.linux-amd64/prometheus
dest: /usr/sbin/prometheus
owner: prometheus
group: prometheus
state: link
- name: Create a symbolic link
ansible.builtin.file:
src: /usr/share/prometheus/prometheus-{{prom_version}}.linux-amd64/promtool
dest: /usr/sbin/promtool
owner: prometheus
group: prometheus
state: link
- name: Copy prometheus.yaml
register: prometheus_config_file
copy:
src: ../../files/prometheus/prometheus.yaml
dest: /etc/prometheus/prometheus.yaml
notify:
- reload prometheus
- name: Copy web-config
register: web_config_file
copy:
src: ../../files/prometheus/web-config.yaml
dest: /etc/prometheus/web-config.yaml
notify:
- reload prometheus
- name: Copy rules.yaml
register: rules_file
copy:
src: ../../files/prometheus/rules.yaml
dest: /etc/prometheus/rules.yaml
notify:
- reload prometheus
- name: Copy alerts.yaml
register: alerts_file
copy:
src: ../../files/prometheus/alerts.yaml
dest: /etc/prometheus/alerts.yaml
notify:
- reload prometheus
- name: Copy prometheus.service
register: prometheus_service_file
copy:
src: ../../files/prometheus/prometheus.service
dest: /etc/systemd/system/prometheus.service
- name: ensure service
ansible.builtin.systemd_service:
name: prometheus
state: started
enabled: true
# - name: reload service
# ansible.builtin.systemd_service:
# name: prometheus
# state: reloaded
# when:
# - rules_file.changed
# - alerts_file.changed
# - prometheus_service_file.changed
# - web_config_file.changed
- name: Just force systemd to reread configs
ansible.builtin.systemd_service:
daemon_reload: true
when: prometheus_service_file.changed
handlers:
- name: reload prometheus
ansible.builtin.systemd_service:
name: prometheus
state: reloaded
#### TODO как откатывать неудачную проверку promtool'ом ?