network/roles/access/templates/config-fs.j2
Timotej Lazar c479f90669 access: move switch config templates back to this repo
Let’s keep it simple. Also editing templates in NetBox is a pain.
2024-04-08 14:45:39 +02:00

42 lines
1.3 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') }}
{% if iface.custom_fields.gateway %}
gateway {{ iface.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 %}