99 lines
2.9 KiB
YAML
99 lines
2.9 KiB
YAML
|
---
|
||
|
- 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 }}"
|
||
|
remote_src: yes
|
||
|
# include:
|
||
|
# - consoles/
|
||
|
# - console_libraries/
|
||
|
# - prometheus
|
||
|
# - promtool
|
||
|
notify: __prometheus_restart
|
||
|
|
||
|
- name: Copy prometheus config file
|
||
|
template:
|
||
|
src: "conf/prometheus.yml.j2"
|
||
|
dest: "{{ prometheus_config_dir }}/prometheus.yml"
|
||
|
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"
|
||
|
mode: 0640
|
||
|
|
||
|
- name: Configure prometheus static targets
|
||
|
template:
|
||
|
src: "conf/file_sd/sd.yml.j2"
|
||
|
dest: "{{ prometheus_file_sd_dir }}/{{ item.name }}.yml"
|
||
|
mode: 0640
|
||
|
loop: "{{ prometheus_targets }}"
|
||
|
|
||
|
- name: Copy prometheus custom static targets
|
||
|
copy:
|
||
|
src: "{{ item }}"
|
||
|
dest: "{{ prometheus_file_sd_dir }}"
|
||
|
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"
|
||
|
mode: 0640
|
||
|
validate: "{{ prometheus_base_dir }}/promtool check rules %s"
|
||
|
when: prometheus_alert_rules + prometheus_alert_rules_extra | length > 0
|
||
|
notify: __prometheus_reload
|
||
|
|
||
|
- name: Copy custom alerting rule files
|
||
|
copy:
|
||
|
src: "{{ item }}"
|
||
|
dest: "{{ prometheus_rules_dir }}/"
|
||
|
mode: 0640
|
||
|
validate: "{{ prometheus_base_dir }}/promtool check rules %s"
|
||
|
with_fileglob: "{{ prometheus_alert_rules_files }}"
|
||
|
notify: __prometheus_reload
|
||
|
become: True
|
||
|
become_user: "{{ prometheus_user }}"
|
||
|
|
||
|
- block:
|
||
|
- 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
|