fabric: use FHRP groups for virtual router IPs

More realistic- and supported-like and also avoids duplicated gateway
addresses.
This commit is contained in:
Timotej Lazar 2024-04-14 15:09:48 +02:00
parent db397cb2b1
commit 2443a90bc5

View file

@ -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 %}