Regardless of terminal width FS switches always split known VLAN ranges into multiple lines of at most twenty numbers when showing configuration. Do the same in our config template to avoid reporting changes when there are none. Allowed VLANs for tagged ports are displayed similarly but even worse, with the first line specifying `allowed vlan only` for the first twenty numbers and subsequent lines adding the remaining VLANs. Not sure if configuring a switch this way – as opposed to a single long `allowed vlan only` line – could disrupt traffic. Instead we simply allow all VLANs on uplink ports, marked in NetBox as 'tagged-all'. For downlink tagged ports the number of allowed VLANs is unlikely to exceed twenty. Ansible now reports no fictional changes for all existing access switches. The only remaining issue is removing known VLANs, which has to be done manually on each switch.
48 lines
1.6 KiB
Django/Jinja
48 lines
1.6 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
|
|
|
|
{% for vlan_range in vlans | map(attribute='vid') | union([1]) | compact_numlist(max_per_line=19) %}
|
|
vlan range {{ vlan_range }}
|
|
{% endfor %}
|
|
|
|
{% 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 }}
|
|
{%- elif iface.mode and iface.mode.value == 'tagged-all' %}
|
|
switchport mode uplink
|
|
switchport trunk allowed vlan only 2-4094
|
|
{% endif %}
|
|
|
|
{% endif %}
|
|
{% endfor %}
|