2022-08-27 11:15:18 +02:00
|
|
|
{{ ansible_managed | comment }}
|
|
|
|
|
|
|
|
global_defs {
|
|
|
|
dynamic_interfaces
|
|
|
|
script_user root
|
|
|
|
enable_script_security
|
|
|
|
vrrp_version 3
|
2022-08-27 13:47:08 +02:00
|
|
|
{% if keepalived__max_auto_priority is defined %}
|
|
|
|
max_auto_priority {{ keepalived__max_auto_priority | int }}
|
|
|
|
{% endif %}
|
2023-04-03 18:02:49 +02:00
|
|
|
{% if keepalived__enable_snmp %}
|
|
|
|
enable_snmp_vrrp
|
|
|
|
enable_snmp_rfc
|
|
|
|
{% endif %}
|
2022-08-27 11:15:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{%
|
|
|
|
set ipv4_enabled =
|
|
|
|
keepalived__ipv4_enabled
|
|
|
|
| default(keepalived__virtual_addresses.values()
|
|
|
|
| flatten | ansible.utils.ipv4)
|
|
|
|
%}
|
|
|
|
{%
|
|
|
|
set ipv6_enabled =
|
|
|
|
keepalived__ipv6_enabled
|
|
|
|
| default(keepalived__virtual_addresses.values()
|
|
|
|
| flatten | ansible.utils.ipv6)
|
|
|
|
%}
|
|
|
|
|
2022-08-27 12:55:53 +02:00
|
|
|
{% if ipv4_enabled and ipv6_enabled %}
|
2022-08-27 11:15:18 +02:00
|
|
|
vrrp_sync_group group {
|
|
|
|
group {
|
|
|
|
{% if ipv4_enabled %}
|
|
|
|
instance_v4
|
|
|
|
{% endif %}
|
|
|
|
{% if ipv6_enabled %}
|
|
|
|
instance_v6
|
|
|
|
{% endif %}
|
|
|
|
}
|
2022-08-27 12:55:53 +02:00
|
|
|
notify_master "/etc/keepalived/notify.sh master"
|
|
|
|
notify_backup "/etc/keepalived/notify.sh backup"
|
|
|
|
notify_fault "/etc/keepalived/notify.sh fault"
|
2022-08-27 11:15:18 +02:00
|
|
|
}
|
2022-08-27 12:55:53 +02:00
|
|
|
{% endif %}
|
2022-08-27 11:15:18 +02:00
|
|
|
|
|
|
|
{% if ipv4_enabled %}
|
|
|
|
vrrp_instance instance_v4 {
|
2022-08-27 13:47:08 +02:00
|
|
|
virtual_router_id {{ keepalived__virtual_router_id | int }}
|
2022-08-27 11:15:18 +02:00
|
|
|
interface {{ keepalived__interface }}
|
|
|
|
state BACKUP
|
2023-01-13 08:53:25 +01:00
|
|
|
priority {{ keepalived__main | ternary(250, 150) }}
|
2022-08-27 11:15:18 +02:00
|
|
|
nopreempt
|
|
|
|
advert_int 1
|
|
|
|
accept
|
|
|
|
virtual_ipaddress {
|
|
|
|
{% for dev, addresses in keepalived__virtual_addresses.items() %}
|
|
|
|
{% for address in addresses %}
|
|
|
|
{% if address | ansible.utils.ipv4 %}
|
|
|
|
{{ address }} dev {{ dev }}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
2022-09-03 14:09:37 +02:00
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
virtual_routes {
|
|
|
|
{% for dev, addresses in keepalived__virtual_routes.items() %}
|
|
|
|
{% for address in addresses %}
|
|
|
|
{% if address | ansible.utils.ipv4 %}
|
|
|
|
{{ address }} dev {{ dev }}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
2022-08-27 11:15:18 +02:00
|
|
|
{% endfor %}
|
|
|
|
}
|
2022-08-27 12:55:53 +02:00
|
|
|
{% 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 %}
|
2022-08-27 11:15:18 +02:00
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if ipv6_enabled %}
|
|
|
|
vrrp_instance instance_v6 {
|
2022-08-27 13:47:08 +02:00
|
|
|
virtual_router_id {{ keepalived__virtual_router_id | int }}
|
2022-08-27 11:15:18 +02:00
|
|
|
interface {{ keepalived__interface }}
|
|
|
|
state BACKUP
|
2023-01-13 08:53:25 +01:00
|
|
|
priority {{ keepalived__main | ternary(250, 150) }}
|
2022-08-27 11:15:18 +02:00
|
|
|
nopreempt
|
|
|
|
advert_int 1
|
|
|
|
accept
|
|
|
|
virtual_ipaddress {
|
|
|
|
{% for dev, addresses in keepalived__virtual_addresses.items() %}
|
2022-08-27 13:47:08 +02:00
|
|
|
{% for address in addresses | ipaddr_sort(["link-local"]) %}
|
2022-08-27 11:15:18 +02:00
|
|
|
{% if address | ansible.utils.ipv6 %}
|
|
|
|
{{ address }} dev {{ dev }}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
2022-09-03 14:09:37 +02:00
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
virtual_routes {
|
|
|
|
{% for dev, addresses in keepalived__virtual_routes.items() %}
|
|
|
|
{% for address in addresses %}
|
|
|
|
{% if address | ansible.utils.ipv6 %}
|
|
|
|
{{ address }} dev {{ dev }}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
2022-08-27 11:15:18 +02:00
|
|
|
{% endfor %}
|
|
|
|
}
|
2022-08-27 12:55:53 +02:00
|
|
|
{% 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 %}
|
2022-08-27 11:15:18 +02:00
|
|
|
}
|
|
|
|
{% endif %}
|