Configure keepalived #100

Merged
jeltz merged 4 commits from keepalived into master 2022-08-30 13:44:29 +02:00
4 changed files with 61 additions and 12 deletions
Showing only changes of commit 9820ae62e8 - Show all commits

View file

@ -1,3 +1,6 @@
---
keepalived__virtual_addresses: {}
keepalived__notify_master: []
keepalived__notify_backup: []
keepalived__notify_fault: []
...

View file

@ -5,11 +5,18 @@
- name: Configure keepalived
template:
src: keepalived.conf.j2
dest: /etc/keepalived/keepalived.conf
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: u=rw,g=,o=
mode: "{{ item.mode }}"
loop:
- src: keepalived.conf.j2
dest: /etc/keepalived/keepalived.conf
mode: u=rw,g=,o=
- src: notify.sh.j2
dest: /etc/keepalived/notify.sh
mode: u=rwx,g=,o=
notify:
- Reload keepalived

View file

@ -20,6 +20,7 @@ set ipv6_enabled =
| flatten | ansible.utils.ipv6)
%}
{% if ipv4_enabled and ipv6_enabled %}
vrrp_sync_group group {
group {
{% if ipv4_enabled %}
@ -29,16 +30,11 @@ vrrp_sync_group group {
instance_v6
{% endif %}
}
{% if keepalived__notify_master is defined %}
notify_master {{ keepalived__notify_master | enquote('"') }}
{% endif %}
{% if keepalived__notify_backup is defined %}
notify_backup {{ keepalived__notify_backup | enquote('"') }}
{% endif %}
{% if keepalived__notify_fault is defined %}
notify_fault {{ keepalived__notify_fault | enquote('"') }}
{% endif %}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
{% endif %}
{% if ipv4_enabled %}
vrrp_instance instance_v4 {
@ -58,6 +54,11 @@ vrrp_instance instance_v4 {
{% endfor %}
{% endfor %}
}
{% if not (ipv4_enabled and ipv6_enabled) %}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
{% endif %}
}
{% endif %}
@ -79,5 +80,10 @@ vrrp_instance instance_v6 {
{% endfor %}
{% endfor %}
}
{% if not (ipv4_enabled and ipv6_enabled) %}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
{% endif %}
}
{% endif %}

View file

@ -0,0 +1,33 @@
#!/bin/bash
master=(
{% for notify in keepalived__notify_master %}
{{ notify | quote }}
{% endfor %}
)
backup=(
{% for notify in keepalived__notify_backup %}
{{ notify | quote }}
{% endfor %}
)
fault=(
{% for notify in keepalived__notify_fault %}
{{ notify | quote }}
{% endfor %}
)
case "$1" in
master | backup | fault)
scripts="$1[@]"
;;
*)
echo "Usage: $0 (master|backup|fault)" >&2
exit 1
esac
for script in "${!scripts}"
do
eval "${script}"
done