diff --git a/roles/firewall/templates/mgmt.intf.j2 b/roles/firewall/templates/mgmt.intf.j2 index 3a94fe9..a1279dd 100644 --- a/roles/firewall/templates/mgmt.intf.j2 +++ b/roles/firewall/templates/mgmt.intf.j2 @@ -18,9 +18,14 @@ iface {{ iface.name }} {% endif %} {% for addr in iface.ip_addresses %} address {{ addr.address }} -{% endfor %} -{% if iface.custom_fields.gateway %} - up ip route add default via {{ iface.custom_fields.gateway.address | ipaddr('address') }}{% if iface.vrf %} vrf {{ iface.vrf.name }}{% endif %} +{% set subnet = addr.address | ipaddr('subnet') %} +{% set prefix_match = prefixes | selectattr('prefix', '==', subnet) %} +{% if prefix_match %} +{% set prefix = prefix_match | first %} +{% if prefix.custom_fields.gateway %} + up ip route add default via {{ prefix.custom_fields.gateway.address | ipaddr('address') }}{% if iface.vrf %} vrf {{ iface.vrf.name }}{% endif %} +{% endif %} {% endif +%} +{% endfor %} {% endfor %}