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 }}"
|
2021-05-29 15:52:24 +00:00
|
|
|
- "{{ prometheus_file_sd_dir }}"
|
2021-05-29 11:45:35 +00:00
|
|
|
|
|
|
|
- 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:47:26 +00:00
|
|
|
exclude:
|
|
|
|
- prometheus-{{ prometheus_version }}.linux-amd64/LICENSE
|
|
|
|
- prometheus-{{ prometheus_version }}.linux-amd64/NOTICE
|
|
|
|
- prometheus-{{ prometheus_version }}.linux-amd64/prometheus.yml
|
2021-05-29 11:45:35 +00:00
|
|
|
notify: __prometheus_restart
|
2021-05-30 12:26:05 +00:00
|
|
|
when: prometheus_version is version(prometheus_current_version, ">") or prometheus_current_version is version('0.0.0', "=")
|
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-06-02 22:06:38 +00:00
|
|
|
mode: 0600
|
2021-05-29 11:45:35 +00:00
|
|
|
validate: "{{ prometheus_base_dir }}/promtool check config %s"
|
|
|
|
notify: __prometheus_reload
|
|
|
|
|
|
|
|
- name: Copy prometheus web config file
|
2021-05-29 13:47:26 +00:00
|
|
|
template:
|
|
|
|
src: "conf/web.yml.j2"
|
2021-05-29 11:45:35 +00:00
|
|
|
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
|
2021-05-29 15:52:24 +00:00
|
|
|
validate: "{{ prometheus_base_dir }}/promtool check web-config %s"
|
2021-05-29 11:45:35 +00:00
|
|
|
|
|
|
|
- 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 }}"
|
2021-05-29 15:52:24 +00:00
|
|
|
loop_control:
|
|
|
|
label: "{{ item.name }}"
|
2021-05-29 11:45:35 +00:00
|
|
|
|
|
|
|
- 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 }}"
|
2021-06-03 19:56:53 +00:00
|
|
|
loop_control:
|
|
|
|
label: "{{ item | basename }}"
|
|
|
|
notify: __prometheus_reload
|
2021-05-29 11:45:35 +00:00
|
|
|
|
|
|
|
- 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 }}"
|
2021-06-03 19:56:53 +00:00
|
|
|
loop_control:
|
|
|
|
label: "{{ item | basename }}"
|
2021-05-29 11:45:35 +00:00
|
|
|
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
|
2021-06-05 13:30:44 +00:00
|
|
|
service:
|
2021-05-29 11:45:35 +00:00
|
|
|
name: prometheus
|
|
|
|
daemon_reload: yes
|
|
|
|
enabled: yes
|
|
|
|
state: started
|
2021-05-29 20:48:56 +00:00
|
|
|
|
|
|
|
- name: Set current version to custom fact
|
|
|
|
template:
|
|
|
|
src: etc/ansible/facts.d/prometheus.fact.j2
|
|
|
|
dest: /etc/ansible/facts.d/prometheus.fact
|
|
|
|
mode: 0644
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
when: prometheus_version is version(prometheus_current_version, ">") or prometheus_current_version is version('0.0.0', "=")
|
2021-05-29 11:45:35 +00:00
|
|
|
become: True
|
|
|
|
become_user: root
|