xoxys.prometheus/tasks/setup.yml

113 lines
3.6 KiB
YAML
Raw Normal View History

2021-05-29 11:45:35 +00:00
---
- name: Prepare base folder
file:
path: "{{ prometheus_base_dir }}"
state: directory
owner: "{{ prometheus_user }}"
group: "{{ prometheus_user }}"
mode: 0750
become: True
become_user: root
- block:
- name: Prepare folder structure
file:
path: "{{ item }}"
state: directory
mode: 0750
loop:
- "{{ prometheus_config_dir }}"
- "{{ prometheus_rules_dir }}"
- "{{ prometheus_data_dir }}"
- name: Download and extract Prometheus tarball
unarchive:
src: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
dest: "{{ prometheus_base_dir }}"
2021-05-29 13:02:57 +00:00
extra_opts:
- --strip-components=1
2021-05-29 11:45:35 +00:00
remote_src: yes
2021-05-29 13:02:57 +00:00
include:
- prometheus-{{ prometheus_version }}.linux-amd64/consoles/
- prometheus-{{ prometheus_version }}.linux-amd64/console_libraries/
- prometheus-{{ prometheus_version }}.linux-amd64/prometheus
- prometheus-{{ prometheus_version }}.linux-amd64/promtool
2021-05-29 11:45:35 +00:00
notify: __prometheus_restart
2021-05-29 13:02:57 +00:00
become: True
become_user: "{{ prometheus_user }}"
2021-05-29 11:45:35 +00:00
2021-05-29 13:02:57 +00:00
- block:
2021-05-29 11:45:35 +00:00
- name: Copy prometheus config file
template:
src: "conf/prometheus.yml.j2"
dest: "{{ prometheus_config_dir }}/prometheus.yml"
2021-05-29 13:02:57 +00:00
owner: "{{ prometheus_user }}"
group: "{{ prometheus_user }}"
2021-05-29 11:45:35 +00:00
mode: 0640
validate: "{{ prometheus_base_dir }}/promtool check config %s"
notify: __prometheus_reload
- name: Copy prometheus web config file
copy:
content: "{{ prometheus_web_config | to_nice_yaml(indent=2) }}"
dest: "{{ prometheus_config_dir }}/web.yml"
2021-05-29 13:02:57 +00:00
owner: "{{ prometheus_user }}"
group: "{{ prometheus_user }}"
2021-05-29 11:45:35 +00:00
mode: 0640
- name: Configure prometheus static targets
template:
src: "conf/file_sd/sd.yml.j2"
dest: "{{ prometheus_file_sd_dir }}/{{ item.name }}.yml"
2021-05-29 13:02:57 +00:00
owner: "{{ prometheus_user }}"
group: "{{ prometheus_user }}"
2021-05-29 11:45:35 +00:00
mode: 0640
loop: "{{ prometheus_targets }}"
- name: Copy prometheus custom static targets
copy:
src: "{{ item }}"
dest: "{{ prometheus_file_sd_dir }}"
2021-05-29 13:02:57 +00:00
owner: "{{ prometheus_user }}"
group: "{{ prometheus_user }}"
2021-05-29 11:45:35 +00:00
mode: 0640
with_fileglob: "{{ prometheus_static_targets_files }}"
- name: Configure prometheus alerting rules
template:
src: "conf/rules/alert.rules.j2"
dest: "{{ prometheus_rules_dir }}/default.rules"
2021-05-29 13:02:57 +00:00
owner: "{{ prometheus_user }}"
group: "{{ prometheus_user }}"
2021-05-29 11:45:35 +00:00
mode: 0640
validate: "{{ prometheus_base_dir }}/promtool check rules %s"
2021-05-29 13:02:57 +00:00
when: (prometheus_alert_rules + prometheus_alert_rules_extra) | length > 0
2021-05-29 11:45:35 +00:00
notify: __prometheus_reload
- name: Copy custom alerting rule files
copy:
src: "{{ item }}"
dest: "{{ prometheus_rules_dir }}/"
2021-05-29 13:02:57 +00:00
owner: "{{ prometheus_user }}"
group: "{{ prometheus_user }}"
2021-05-29 11:45:35 +00:00
mode: 0640
validate: "{{ prometheus_base_dir }}/promtool check rules %s"
with_fileglob: "{{ prometheus_alert_rules_files }}"
notify: __prometheus_reload
- name: Copy systemd unit file
template:
src: "etc/systemd/system/prometheus.service.j2"
dest: "/etc/systemd/system/prometheus.service"
mode: 0640
notify: __prometheus_restart
- name: Ensure prometheus service is up and running
systemd:
name: prometheus
daemon_reload: yes
enabled: yes
state: started
become: True
become_user: root