network/roles/access/templates/config-fs.j2

54 lines
1.8 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 %}
{% for address in iface.ip_addresses %}
{% set subnet = address.address | ipaddr('subnet') %}
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
{% if address.family.value == 4 %}
ip address {{ address.address | ipaddr('address') }} {{ address.address | ipaddr('netmask') }}
{% if prefix.custom_fields.gateway %}
gateway {{ prefix.custom_fields.gateway.address | ipaddr('address') }}
{% endif %}
{% else %}
ipv6 address {{ address.address | upper }}
{% if prefix.custom_fields.gateway %}
ipv6 gateway {{ prefix.custom_fields.gateway.address | ipaddr('address') | upper }}
{% endif %}
{% endif %}
{% endfor %}
{% 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 %}