2023-07-14 09:29:04 +00:00
|
|
|
---
|
2024-10-14 16:01:29 +00:00
|
|
|
- name: Ensure state is valid
|
|
|
|
ansible.builtin.fail:
|
|
|
|
msg: >-2
|
|
|
|
Invalid state '{{ alertmanager_state }}'! Valid
|
|
|
|
states are {{ alertmanager_states | join(', ') }}.
|
|
|
|
when: alertmanager_state not in alertmanager_states
|
2023-07-14 09:29:04 +00:00
|
|
|
|
2024-10-14 16:01:29 +00:00
|
|
|
- name: Ensure deployment method is valid
|
|
|
|
ansible.builtin.fail:
|
|
|
|
msg: >-2
|
|
|
|
Invalid deployment method {{ alertmanager_deployment_method }}!
|
|
|
|
Supported deployment methods are {{ alertmanager_deployment_methods | join(', ') }}.
|
|
|
|
when: alertmanager_deployment_method not in alertmanager_deployment_methods
|
|
|
|
|
|
|
|
- name: Ensure alertmanager user '{{ alertmanager_user }}' is {{ alertmanager_state }}
|
2023-07-14 09:29:04 +00:00
|
|
|
ansible.builtin.user:
|
|
|
|
name: "{{ alertmanager_user }}"
|
2024-10-14 16:01:29 +00:00
|
|
|
state: "{{ alertmanager_state }}"
|
2023-07-14 09:29:04 +00:00
|
|
|
system: true
|
|
|
|
register: alertmanager_user_info
|
|
|
|
|
2024-10-14 16:01:29 +00:00
|
|
|
- name: Ensure mounts are {{ alertmanager_state }}
|
2023-07-14 09:29:04 +00:00
|
|
|
ansible.builtin.file:
|
|
|
|
dest: "{{ item.path }}"
|
2024-10-14 16:01:29 +00:00
|
|
|
state: "{{ (alertmanager_state == 'present') | ternary('directory', 'absent') }}"
|
2023-07-14 09:29:04 +00:00
|
|
|
owner: "{{ item.owner | default(alertmanager_user_info.uid | default(alertmanager_user)) }}"
|
|
|
|
group: "{{ item.owner | default(alertmanager_user_info.group | default(alertmanager_user)) }}"
|
|
|
|
mode: "{{ item.mode | default('0755') }}"
|
|
|
|
loop:
|
|
|
|
- path: "{{ alertmanager_base_path }}"
|
|
|
|
- path: "{{ alertmanager_data_path }}"
|
|
|
|
- path: "{{ alertmanager_config_path }}"
|
|
|
|
|
|
|
|
- name: Ensure config file is templated
|
|
|
|
ansible.builtin.copy:
|
|
|
|
dest: "{{ alertmanager_config_file }}"
|
|
|
|
content: "{{ alertmanager_config | to_nice_yaml }}"
|
|
|
|
owner: "{{ alertmanager_user_info.uid | default(alertmanager_user) }}"
|
2024-10-14 16:01:29 +00:00
|
|
|
group: "{{ alertmanager_user_info.group | default(alertmanager_user) }}"
|
2023-07-14 09:29:04 +00:00
|
|
|
mode: "0640"
|
2024-10-14 16:01:29 +00:00
|
|
|
when: alertmanager_state == 'present'
|
2023-07-14 09:29:04 +00:00
|
|
|
notify:
|
|
|
|
- restart-alertmanager
|
|
|
|
|
2024-10-14 16:01:29 +00:00
|
|
|
- name: Deploy alertmanager using {{ alertmanager_deployment_method }}
|
|
|
|
ansible.builtin.include_tasks:
|
|
|
|
file: "deploy-{{ alertmanager_deployment_method }}.yml"
|