Skip to content

Commit 030c1ab

Browse files
authored
Merge pull request #391 from Normo/keepalived-notification-email
Convert keepalived_notification_email to a list
2 parents 6b7b9ec + 899fedf commit 030c1ab

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

molecule/keepalived/converge.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
- name: "Converge"
99
hosts: "all"
10-
vars:
11-
keepalived_unicast_peers:
12-
- "172.17.0.3"
13-
- "172.17.0.4"
14-
keepalived_virtual_ip_address: "172.17.0.20"
1510
tasks:
1611
- name: "Include keepalived role"
1712
ansible.builtin.include_role:

molecule/keepalived/molecule.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ provisioner:
2727
check: "converge.yml"
2828
converge: "converge.yml"
2929
verify: "verify.yml"
30+
inventory:
31+
hosts:
32+
all:
33+
vars:
34+
keepalived_unicast_peers:
35+
- "172.17.0.3"
36+
- "172.17.0.4"
37+
keepalived_virtual_ip_address: "172.17.0.20"
38+
keepalived_notification_email: "[email protected]"
39+
# keepalived_notification_emails:
40+
# - "root@localhost"
41+
3042
verifier:
3143
name: "ansible"
3244
scenario:

roles/keepalived/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ keepalived_pid_file_path: "/run/keepalived/keepalived.pid"
153153

154154
#### Configure notification email address
155155

156-
Configure recipient of notification emails:
156+
List of email accounts that will receive notification mails:
157157

158158
```yaml
159-
keepalived_notification_email: 'name@localhost'
159+
keepalived_notification_emails:
160+
- 'root@localhost'
160161
```
161162

162163
#### Configure notification sender

roles/keepalived/defaults/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ keepalived_service_file_path: "/etc/systemd/system/keepalived.service"
4444
keepalived_pid_file_path: "/run/keepalived/keepalived.pid"
4545

4646

47-
# Configure notification email address
48-
keepalived_notification_email: "name@localhost"
47+
# Configure email accounts that will receive notification mails
48+
keepalived_notification_emails: ["root@localhost"]
4949
# Configure notification sender
5050
keepalived_notification_email_from: "keepalived@localhost"
5151
# Configure SMTP Server

roles/keepalived/tasks/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
fail_msg: "Some mandatory variables are not set."
1414
success_msg: "All mandatory variables are set."
1515

16+
- name: "Variable keepalived_notification_email is deprecated"
17+
when: "keepalived_notification_email | default('') | length > 0"
18+
block:
19+
20+
- name: "Set keepalived_notification_emails variable"
21+
ansible.builtin.set_fact:
22+
keepalived_notification_emails: ["{{ keepalived_notification_email }}"]
23+
24+
- name: "Show deprecation warning"
25+
ansible.builtin.debug:
26+
msg:
27+
- "The variable keepalived_notification_email is deprecated and will be removed in the next major release."
28+
- "Please use list variable 'keepalived_notification_emails' instead."
29+
1630
- name: "Install dependencies for Keepalived."
1731
become: true
1832
ansible.builtin.package:

roles/keepalived/templates/keepalived.conf.j2

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ global_defs {
1111
{% if keepalived_set_script_security_flag %}
1212
enable_script_security
1313
{% endif %}
14+
{% if keepalived_notification_emails | default([]) | length > 0 %}
1415
notification_email {
15-
{{ keepalived_notification_email }}
16+
{% for email in keepalived_notification_emails %}
17+
{{ email }}
18+
{% endfor %}
1619
}
1720
notification_email_from {{ keepalived_notification_email_from }}
1821
smtp_server {{ keepalived_smtp_server }}
1922
smtp_connect_timeout 30
23+
{% endif %}
2024
{% if keepalived_router_id is defined %}
2125
router_id {{ keepalived_router_id }}
2226
{% endif %}

0 commit comments

Comments
 (0)