From 2443a90bc58a3fdf36f00fd0ab0410f5b992338a Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 14 Apr 2024 15:09:48 +0200 Subject: [PATCH] fabric: use FHRP groups for virtual router IPs More realistic- and supported-like and also avoids duplicated gateway addresses. --- roles/fabric/templates/switch.intf.j2 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/roles/fabric/templates/switch.intf.j2 b/roles/fabric/templates/switch.intf.j2 index dfe633c..977c091 100644 --- a/roles/fabric/templates/switch.intf.j2 +++ b/roles/fabric/templates/switch.intf.j2 @@ -1,3 +1,6 @@ +{% set fhrp_assignments = query('netbox.netbox.nb_lookup', 'fhrp-group-assignments', raw_data=true) %} +{% set fhrp_groups = query('netbox.netbox.nb_lookup', 'fhrp-groups', raw_data=true) -%} + {% for iface in interfaces | rejectattr('name', 'in', ('lo', 'bridge')) | rejectattr('mgmt_only') | selectattr('enabled') %} auto {{ iface.name }} iface {{ iface.name }} @@ -37,13 +40,13 @@ iface {{ iface.name }} {% endif %} {#- Addresses. #} -{% for addr in iface.ip_addresses | rejectattr('role') %} +{% for addr in iface.ip_addresses %} address {{ addr.address }} {% endfor %} -{% set anycast = iface.ip_addresses | selectattr('role') | selectattr('role.value', '==', 'anycast') - | map(attribute='address') %} -{% if anycast %} - address-virtual 00:00:5e:00:01:01 {{ anycast | ipaddr(1) | join(' ') }} +{% if iface.count_fhrp_groups > 0 %} +{% set fhrp_assignment = fhrp_assignments | selectattr('interface.id', '==', iface.id) | first %} +{% set fhrp_group = fhrp_groups | selectattr('id', '==', fhrp_assignment.group.id) | first %} + address-virtual 00:00:5e:00:01:01 {{ fhrp_group.ip_addresses | sort(attribute='family') | map(attribute='address') | join(' ') }} {% endif %} {% endfor %}