
上QQ阅读APP看书,第一时间看更新
How it works...
We are using the same data structure in the lan.yml file that defines all the interfaces within the LAN network and describes their type (access/trunk). In the case of access ports, we define which access interface is part of which VLAN. We will reference this list data structure to configure the access and trunk ports on all the devices within the lan group.
The interfaces within our layer2 network are one of the following two options:
Access:
- We use ios_l2_interface with the access_vlan parameter to configure the correct access VLAN on the interface.
- We select only the access interfaces for each device using the selectattr jinja2 filter, and we match only one interface with a mode equal to access, and we loop over this list for each device.
Trunk:
- We use ios_l2_interface with the trunk_allowed_vlans parameter to add all the VLANs to the trunk ports, on both access and core switches.
- We create the permitted VLAN list using the Jinja2 map and join filters and we apply this filter to the vlans list data structure. This outputs a string similar to the following: 10,20,100.
- We select only the trunk ports using the selectattr Jinja2 filter from the interface's data structure per node.
- We need to configure these trunks as dot1q ports; however, this attribute is still not enabled on ios_l2_interface. Hence, we use another module, ios_config, to send the required Cisco IOS command to set up the dot1q trunks.
The following output outlines the configuration applied to the access01 device as an example for both access and trunk ports:
!
interface Ethernet0/3 >> Access Port
description Data_vlan
switchport access vlan 10
switchport mode access
!
interface Ethernet0/1 >> Trunk Port
description core01_e0/1
switchport trunk encapsulation dot1q
switchport trunk allowed vlan 10,20,100
switchport mode trunk