xoxys.alertmanager/tasks/setup.yml
Robert Kaussow af97c37a71
Some checks failed
continuous-integration/drone/push Build is failing
feat: add reload handler
2021-06-05 22:54:19 +02:00

95 lines
3.1 KiB
YAML

---
- 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
validate: "{{ alertmanager_base_dir }}/amtool check-config %s"
notify: __alertmanager_reload
- 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
notify: __alertmanager_reload
- 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:
label: "{{ item | basename }}"
notify: __alertmanager_reload
- 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:
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