xoxys.alertmanager/tasks/setup.yml

95 lines
3.1 KiB
YAML
Raw Permalink Normal View History

2021-06-02 22:01:24 +00:00
---
- name: Prepare base folder
file:
path: "{{ alertmanager_base_dir }}"
state: directory
owner: "{{ alertmanager_user }}"
group: "{{ alertmanager_user }}"
mode: 0750
become: True
become_user: root
- block:
- name: Prepare folder structure
file:
path: "{{ item }}"
state: directory
mode: 0750
loop:
- "{{ alertmanager_config_dir }}"
- "{{ alertmanager_templates_dir }}"
- "{{ alertmanager_data_dir }}"
- name: Download and extract Alertmanager tarball
unarchive:
src: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/alertmanager-{{ alertmanager_version }}.linux-amd64.tar.gz"
dest: "{{ alertmanager_base_dir }}"
extra_opts:
- --strip-components=1
remote_src: yes
exclude:
- alertmanager-{{ alertmanager_version }}.linux-amd64/LICENSE
- alertmanager-{{ alertmanager_version }}.linux-amd64/NOTICE
- alertmanager-{{ alertmanager_version }}.linux-amd64/alertmanager.yml
notify: __alertmanager_restart
when: alertmanager_version is version(alertmanager_current_version, ">") or alertmanager_current_version is version('0.0.0', "=")
become: True
become_user: "{{ alertmanager_user }}"
- block:
- name: Copy alertmanager config file
template:
src: "conf/alertmanager.yml.j2"
dest: "{{ alertmanager_config_dir }}/alertmanager.yml"
owner: "{{ alertmanager_user }}"
group: "{{ alertmanager_user }}"
mode: 0600
2021-06-02 22:01:24 +00:00
validate: "{{ alertmanager_base_dir }}/amtool check-config %s"
2021-06-05 20:54:19 +00:00
notify: __alertmanager_reload
2021-06-02 22:01:24 +00:00
- name: Copy alertmanager web config file
template:
src: "conf/web.yml.j2"
dest: "{{ alertmanager_config_dir }}/web.yml"
owner: "{{ alertmanager_user }}"
group: "{{ alertmanager_user }}"
mode: 0640
2021-06-05 20:54:19 +00:00
notify: __alertmanager_reload
2021-06-02 22:01:24 +00:00
- name: Copy custom Alertmanager template files
copy:
src: "{{ item }}"
dest: "{{ alertmanager_templates_dir }}"
owner: "{{ alertmanager_user }}"
group: "{{ alertmanager_user }}"
mode: 0640
with_fileglob: "{{ alertmanager_template_files }}"
loop_control:
2021-06-03 19:58:33 +00:00
label: "{{ item | basename }}"
2021-06-05 20:54:19 +00:00
notify: __alertmanager_reload
2021-06-02 22:01:24 +00:00
- name: Copy systemd unit file
template:
src: "etc/systemd/system/alertmanager.service.j2"
dest: "/etc/systemd/system/alertmanager.service"
mode: 0640
notify: __alertmanager_restart
- name: Ensure alertmanager service is up and running
service:
2021-06-02 22:01:24 +00:00
name: alertmanager
daemon_reload: yes
enabled: yes
state: started
- name: Set current version to custom fact
template:
src: etc/ansible/facts.d/alertmanager.fact.j2
dest: /etc/ansible/facts.d/alertmanager.fact
mode: 0644
owner: root
group: root
when: alertmanager_version is version(alertmanager_current_version, ">") or alertmanager_current_version is version('0.0.0', "=")
become: True
become_user: root