ansible-collection-prometheus/roles/alertmanager/tasks/install.yml
gardar 9f4c0243e5
refactor: support customizing alertmanager url/mirror
Signed-off-by: gardar <gardar@users.noreply.github.com>
2023-03-02 12:49:34 +00:00

83 lines
2.4 KiB
YAML

---
- name: Create alertmanager system group
ansible.builtin.group:
name: alertmanager
system: true
state: present
- name: Create alertmanager system user
ansible.builtin.user:
name: alertmanager
system: true
shell: "/usr/sbin/nologin"
group: alertmanager
createhome: false
- name: Create alertmanager directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: alertmanager
group: alertmanager
mode: 0755
with_items:
- "{{ alertmanager_config_dir }}"
- "{{ alertmanager_config_dir }}/templates"
- "{{ alertmanager_db_dir }}"
- "{{ _alertmanager_amtool_config_dir }}"
- name: Get alertmanager binary
when: alertmanager_binary_local_dir | length == 0
block:
- name: Download alertmanager binary to local folder
become: false
ansible.builtin.get_url:
url: "{{ alertmanager_binary_url }}"
dest: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz"
checksum: "sha256:{{ __alertmanager_checksum }}"
mode: 0644
register: _download_archive
until: _download_archive is succeeded
retries: 5
delay: 2
# run_once: true # <-- this can't be set due to multi-arch support
delegate_to: localhost
check_mode: false
- name: Unpack alertmanager binaries
become: false
ansible.builtin.unarchive:
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
- name: Propagate official alertmanager and amtool binaries
ansible.builtin.copy:
src: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}/{{ item }}"
dest: "{{ _alertmanager_binary_install_dir }}/{{ item }}"
mode: 0755
owner: root
group: root
with_items:
- alertmanager
- amtool
notify:
- restart alertmanager
- name: Propagate locally distributed alertmanager and amtool binaries
ansible.builtin.copy:
src: "{{ alertmanager_binary_local_dir }}/{{ item }}"
dest: "{{ _alertmanager_binary_install_dir }}/{{ item }}"
mode: 0755
owner: root
group: root
with_items:
- alertmanager
- amtool
when: alertmanager_binary_local_dir | length > 0
notify:
- restart alertmanager