ansible/roles/ifstated/templates/ifstated-dna.conf.j2

54 lines
1.6 KiB
Django/Jinja

init-state auto
if_carp_up="carp1.link.up"
if_carp_down="carp1.link.down"
state auto {
if $if_carp_up {
set-state master
}
if $if_carp_down {
set-state backup
}
}
state master {
init {
# spoof mac to keep dhcp lease in sync with both gw's
run "/sbin/ifconfig vio1 lladdr {{ lookup('vars', 'gw_mac_' + inventory_hostname.split('.')[1]) }} up"
# flush routes and renew lease
run "/sbin/route -qn flush"
run "/usr/sbin/dhcpleasectl vio1"
# reset firewall rules
run "sleep 5 ; pfctl -f /etc/pf.conf"
}
if $if_carp_down {
set-state backup
}
}
state backup {
init {
# bring down interface and reset mac
run "/sbin/ifconfig vio1 delete lladdr {{ lookup('vars', 'gw_mac_' + inventory_hostname.split('.')[1]) }} down"
# flush routes and fix default route
run "/sbin/route -qn flush"
{% if inventory_hostname == "dna-gw01.home.foo.sh" %}
run "/sbin/route -qn add default 172.20.21.2"
{% elif inventory_hostname == "dna-gw02.home.foo.sh" %}
run "/sbin/route -qn add default 172.20.21.1"
{% elif inventory_hostname == "dna-gw03.lan.foo.sh" %}
run "/sbin/route -qn add default 172.20.30.4"
{% elif inventory_hostname == "dna-gw04.lan.foo.sh" %}
run "/sbin/route -qn add default 172.20.30.3"
{% elif inventory_hostname == "dna-gw05.iot.foo.sh" %}
run "/sbin/route -qn add default 172.20.27.6"
{% elif inventory_hostname == "dna-gw06.iot.foo.sh" %}
run "/sbin/route -qn add default 172.20.27.5"
{% endif %}
}
if $if_carp_up {
set-state master
}
}