2022-09-22 14:38:42 +00:00
|
|
|
---
|
2022-09-23 12:07:54 +00:00
|
|
|
- name: Create alertmanager system group
|
|
|
|
ansible.builtin.group:
|
2022-09-22 14:38:42 +00:00
|
|
|
name: alertmanager
|
|
|
|
system: true
|
|
|
|
state: present
|
|
|
|
|
2022-09-23 12:07:54 +00:00
|
|
|
- name: Create alertmanager system user
|
|
|
|
ansible.builtin.user:
|
2022-09-22 14:38:42 +00:00
|
|
|
name: alertmanager
|
|
|
|
system: true
|
|
|
|
shell: "/usr/sbin/nologin"
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.group: alertmanager
|
2022-09-22 14:38:42 +00:00
|
|
|
createhome: false
|
|
|
|
|
2022-09-23 12:07:54 +00:00
|
|
|
- name: Create alertmanager directories
|
|
|
|
ansible.builtin.file:
|
2022-09-22 14:38:42 +00:00
|
|
|
path: "{{ item }}"
|
|
|
|
state: directory
|
|
|
|
owner: alertmanager
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.group: alertmanager
|
2022-09-22 14:38:42 +00:00
|
|
|
mode: 0755
|
|
|
|
with_items:
|
|
|
|
- "{{ alertmanager_config_dir }}"
|
|
|
|
- "{{ alertmanager_config_dir }}/templates"
|
|
|
|
- "{{ alertmanager_db_dir }}"
|
|
|
|
- "{{ _alertmanager_amtool_config_dir }}"
|
|
|
|
|
2022-11-25 10:37:52 +00:00
|
|
|
- name: Get alertmanager binary
|
|
|
|
when: alertmanager_binary_local_dir | length == 0
|
|
|
|
block:
|
|
|
|
|
|
|
|
- name: Download alertmanager binary to local folder
|
2022-09-22 14:38:42 +00:00
|
|
|
become: false
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.get_url:
|
2022-11-25 13:53:37 +00:00
|
|
|
url: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/
|
|
|
|
alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz"
|
2022-09-22 14:38:42 +00:00
|
|
|
dest: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz"
|
|
|
|
checksum: "sha256:{{ __alertmanager_checksum }}"
|
2022-11-25 13:53:37 +00:00
|
|
|
mode: 0644
|
2022-09-22 14:38:42 +00:00
|
|
|
register: _download_archive
|
|
|
|
until: _download_archive is succeeded
|
|
|
|
retries: 5
|
|
|
|
delay: 2
|
2022-11-25 10:37:52 +00:00
|
|
|
# run_once: true # <-- this can't be set due to multi-arch support
|
2022-09-22 14:38:42 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
check_mode: false
|
|
|
|
|
2022-11-25 10:37:52 +00:00
|
|
|
- name: Unpack alertmanager binaries
|
2022-09-22 14:38:42 +00:00
|
|
|
become: false
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.unarchive:
|
2022-09-22 14:38:42 +00:00
|
|
|
src: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz"
|
|
|
|
dest: "/tmp"
|
|
|
|
mode: 0755
|
|
|
|
creates: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}/alertmanager"
|
|
|
|
delegate_to: localhost
|
|
|
|
check_mode: false
|
|
|
|
|
2022-11-25 10:37:52 +00:00
|
|
|
- name: Propagate official alertmanager and amtool binaries
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.copy:
|
2022-09-22 14:38:42 +00:00
|
|
|
src: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}/{{ item }}"
|
|
|
|
dest: "{{ _alertmanager_binary_install_dir }}/{{ item }}"
|
|
|
|
mode: 0755
|
|
|
|
owner: root
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.group: root
|
2022-09-22 14:38:42 +00:00
|
|
|
with_items:
|
|
|
|
- alertmanager
|
|
|
|
- amtool
|
|
|
|
notify:
|
|
|
|
- restart alertmanager
|
|
|
|
|
2022-11-25 10:37:52 +00:00
|
|
|
- name: Propagate locally distributed alertmanager and amtool binaries
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.copy:
|
2022-09-22 14:38:42 +00:00
|
|
|
src: "{{ alertmanager_binary_local_dir }}/{{ item }}"
|
|
|
|
dest: "{{ _alertmanager_binary_install_dir }}/{{ item }}"
|
|
|
|
mode: 0755
|
|
|
|
owner: root
|
2022-09-23 12:07:54 +00:00
|
|
|
ansible.builtin.group: root
|
2022-09-22 14:38:42 +00:00
|
|
|
with_items:
|
|
|
|
- alertmanager
|
|
|
|
- amtool
|
|
|
|
when: alertmanager_binary_local_dir | length > 0
|
|
|
|
notify:
|
|
|
|
- restart alertmanager
|