blob: e4670f74b3f4bf661016eecbfce4fe3648b81426 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
---
- 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"
- name: generate apt pin file for alertmanager package
when: prometheus_alertmanager_version is defined
copy:
dest: "/etc/apt/preferences.d/prom-alertmanager.pref"
content: |
Package: prom-alertmanager
Pin: version {{ prometheus_alertmanager_version }}-1
Pin-Priority: 1001
- name: remove apt pin file for alertmanager package
when: prometheus_alertmanager_version is not defined
file:
path: "/etc/apt/preferences.d/prom-alertmanager.pref"
state: absent
- name: install apt packages
apt:
name: "prom-alertmanager{% if prometheus_alertmanager_version is defined %}={{ prometheus_alertmanager_version }}-1{% endif %}"
state: present
allow_downgrade: yes
notify: restart prometheus-alertmanager
- 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
validate: "amtool check-config %s"
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
|