# Management VRF and link. auto mgmt iface mgmt address 127.0.0.1/8 address ::1/128 vrf-table auto {% for iface in hostvars[inventory_hostname].interfaces | selectattr('name', 'match', '^mgmt') | selectattr('ip_addresses') %} auto {{ iface.name }} iface {{ iface.name }} vrf mgmt {% for ip in iface.ip_addresses %} address {{ ip.address }} {% set subnet = ip.address | ipaddr('subnet') %} {% set prefix = query('netbox.netbox.nb_lookup', 'prefixes', api_filter=('prefix='+subnet))|first %} {% set gateway = prefix.value.custom_fields.gateway.address %} {% if gateway is defined %} gateway {{ gateway | ipaddr('address') }} {% endif %} {% endfor %} {% endfor %} source /etc/network/interfaces.d/*