Configure keepalived #100
4 changed files with 61 additions and 12 deletions
|
@ -1,3 +1,6 @@
|
|||
---
|
||||
keepalived__virtual_addresses: {}
|
||||
keepalived__notify_master: []
|
||||
keepalived__notify_backup: []
|
||||
keepalived__notify_fault: []
|
||||
...
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 %}
|
||||
|
|
33
roles/keepalived/templates/notify.sh.j2
Normal file
33
roles/keepalived/templates/notify.sh.j2
Normal 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
|
Loading…
Reference in a new issue