summaryrefslogtreecommitdiffstats
path: root/roles/keepalived/templates/keepalived.conf.j2
blob: 6df5eab2772718c92547391d3682a6e659bdb8ce (plain)
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
global_defs {
}

vrrp_script track {
    script "[ -f /etc/keepalived/track.sh ] || exit 0 && /etc/keepalived/track.sh"
    interval {{ keepalived_check_interval }}
}

{% for vrrp in keepalived_vrrp  %}
{%   set vrrp_id = loop.index %}
{%   for vips in vrrp.vips  %}
{%     set id = (  vips | ipaddr('address') | regex_replace('^.*\.', '') ) %}

vrrp_instance VI_{{vrrp_id}}_{{ loop.index }} {

    virtual_router_id {{ (vrrp_id - 1) * 32 + (loop.index) }}

    state {{ (( ( loop.index - 1) % (keepalived_num_nodes | int) ) == (keepalived_node_id | int) ) | ternary('MASTER', 'BACKUP') }}
    state {{ (( ( loop.index - 1) % (keepalived_num_nodes | int) ) == (keepalived_node_id | int) ) | ternary(keepalived_master_prio, keepalived_backup_prio) }}

    interface {{ vrrp.iface }}

    virtual_ipaddress {
        {{ vips }} dev {{ vrrp.iface }} 
    }
    
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass {{ keepalived_password }}
    }

    track_script {
        track
    }
}
{%   endfor %}
{% endfor %}