network/roles/access/templates/config-fs.j2
Timotej Lazar 0ed4973894 access: get mgmt gateway from custom field on prefix
Mainly so we can drop the gateway custom field from NetBox interfaces.
2025-03-24 18:13:55 +01:00

44 lines
1.4 KiB
Django/Jinja

hostname {{ inventory_hostname }}
no netconf enable
no enable service telnet-server
no enable service web-server http
no enable service web-server https
vlan range {{ vlans | map(attribute='vid') | union([1]) | compact_numlist }}
{% for iface in interfaces %}
interface {{ iface.name }}
{% if iface.enabled %} no{% endif %} shutdown
{% if iface.lag %}
port-group {{ iface.lag.name | select('in', '0123456789') | join('') }} mode active
{% elif iface.mgmt_only %}
{% if iface.ip_addresses %}
{% set address = iface.ip_addresses | map(attribute='address') | first %}
ip address {{ address | ipaddr('address') }} {{ address | ipaddr('netmask') }}
{% set subnet = address | ipaddr('subnet') %}
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
{% if prefix.custom_fields.gateway %}
gateway {{ prefix.custom_fields.gateway.address | ipaddr('address') }}
{%- endif %}
{%- endif %}
{% else %}
mtu {{ iface.mtu | default('9216', true) }}
{% if iface.mode and iface.mode.value == 'access' %}
switchport mode access
{% if iface.untagged_vlan and iface.untagged_vlan.vid != 1 %}
switchport access vlan {{ iface.untagged_vlan.vid }}
{% else %}
no switchport access vlan
{% endif %}
{%- elif iface.mode and iface.mode.value == 'tagged' %}
switchport mode trunk
switchport trunk allowed vlan only {{ (iface.tagged_vlans or vlans) | map(attribute='vid') | compact_numlist }}
{% endif %}
{% endif %}
{% endfor %}