{% if globals|length %}
global_defs {
    {% if globals['vrrp_garp_master_refresh'] is defined %}vrrp_garp_master_refresh {{ globals['vrrp_garp_master_refresh'] }}{% endif %}
}
{% endif %}

{%- for item in vrrp_ips %}
vrrp_script script_{{ item['id'] }} {
    script       "/usr/local/bin/check_haproxy.sh"
    interval 2
    fall 2
    rise 2
}


vrrp_instance balancer_{{ item['id'] }} {
    state BACKUP
    interface {{ item['interface'] }}
    virtual_router_id {{ item['router_id'] }}
    priority {{ item['priority'] }}
    nopreempt
    virtual_ipaddress {
        {{ item['ip'] }} dev {{ item['interface'] }} label vip_{{ item['id'] }}
    }

    track_script {
        script_{{ item['id'] }}
    }

    authentication {
        auth_type PASS
        auth_pass {{ item['password'] }}
    }

{%- if item['peers'] | length > 0 %}
    unicast_src_ip {{ item['source'] }}
    unicast_peer {
{%- for ip in item['peers'] %}
        {{ ip }}
{%- endfor %}
    }
{%- endif %}
}

{%- endfor %}
