summaryrefslogtreecommitdiff
path: root/roles/monitoring/prometheus/alertmanager/tasks/main.yml
blob: 173ea7588fcf0075387cce19270cef18fff33f41 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
- name: check if prometheus apt component of spreadspace repo is enabled
  assert:
    msg: "please enable the 'prometheus' component of spreadspace repo using 'spreadspace_apt_repo_components'"
    that:
    - spreadspace_apt_repo_components is defined
    - "'prometheus' in spreadspace_apt_repo_components"

  ## TODO: pin version
- name: install apt packages
  apt:
    name: prom-alertmanager
    state: present

- name: add user for alertmanager
  user:
    name: prometheus-alertmanager
    system: yes
    home: /nonexistent
    create_home: no

- name: create data directory
  file:
    path: /var/lib/prometheus/alertmanager
    state: directory
    owner: prometheus-alertmanager
    group: prometheus-alertmanager

- name: generate configuration file
  template:
    src: alertmanager.yml.j2
    dest: /etc/prometheus/alertmanager.yml
  notify: reload prometheus-alertmanager

- name: generate web configuration file
  when: prometheus_alertmanager_auth_users is defined
  copy:
    content: |
      # Ansible managed
      basic_auth_users:
      {% for user,password in prometheus_alertmanager_auth_users.items() %}
        {{ user }}: {{ password | password_hash('bcrypt', (user~'@'~inventory_hostname~'/prometheus/alertmanager') | bcrypt_salt) }}
      {% endfor %}
    dest: /etc/prometheus/alertmanager-web.yml
    mode: 0640
    owner: root
    group: prometheus-alertmanager
  notify: reload prometheus-alertmanager

- name: generate password files
  when: prometheus_alertmanager_password_files is defined
  loop: "{{ prometheus_alertmanager_password_files | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  copy:
    content: "{{ item.value }}"
    dest: "/etc/prometheus/alertmanager-{{ item.key }}.password"
    mode: 0640
    owner: root
    group: prometheus-alertmanager
  notify: reload prometheus-alertmanager

- name: generate systemd service unit
  template:
    src: prometheus-alertmanager.service.j2
    dest: /etc/systemd/system/prometheus-alertmanager.service
  notify: restart prometheus-alertmanager

- name: make sure alertmanager is enabled and started
  systemd:
    name: prometheus-alertmanager.service
    daemon_reload: yes
    state: started
    enabled: yes