In this recipe, we will outline how to configure the basic interface properties on Cisco IOS-based devices, such as setting the interface description, the interface maximum transmission unit (MTU), and enabling interfaces. We will configure all the links within our topology as having a link MTU of 1,500 and to be fully duplex.
Configuring interfaces on IOS devices
Getting ready
To follow along with this recipe, an Ansible inventory is assumed to be already set up, as is IP reachability between the Ansible control node with the Cisco devices in place.
How to do it...
- In the group_vars/network.yml file, add the following content to define the generic interface parameters:
$ cat group_vars/network.yml
<-- Output Trimmed for brevity ------>
intf_duplex: full
intf_mtu: 1500
- Create a new file, lan.yml, under the group_vars folder, with the following data to define the interfaces on our Cisco devices:
$ cat group_vars/lan.yaml
interfaces:
core01:
- name: Ethernet0/1
description: access01_e0/1
mode: trunk
- name: Ethernet0/2
description: access02_e0/1
mode: trunk
- name: Ethernet0/3
description: core01_e0/3
mode: trunk
<-- Output Trimmed for brevity ------>
access01:
- name: Ethernet0/1
description: core01_e0/1
mode: trunk
- name: Ethernet0/2
description: core02_e0/1
mode: trunk
- name: Ethernet0/3
description: Data_vlan
mode: access
vlan: 10
- Update the pb_build_network.yml playbook file with the following task to set up the interfaces:
- name: "P1T3: Configure Interfaces"
ios_interface:
name: "{{ item.name }}"
description: "{{ item.description }}"
duplex: "{{ intf_duplex }}"
mtu: "{{ intf_mtu }}"
state: up
loop: "{{ interfaces[inventory_hostname] }}"
register: ios_intf
How it works...
In this recipe, we outline how to configure the physical interfaces on IOS devices. We first declare the generic parameters (interface duplex and MTU) that apply to all the interfaces. These parameters are defined under the network.yml file. Next, we define all the interface-specific parameters for all our LAN devices under the lan.yml file to be applied to all devices. All these parameters are declared in the interfaces dictionary data structure.
We update our playbook with a new task to configure the physical parameters for all of our LAN devices in our network. We use the ios_interface module to provision all the interface parameters, and we loop over all the interfaces in each node using the interfaces data structure. We set the state to up in order to indicate that the interface should be present and operational.
See also...
For more information regarding the ios_interface module, and the different parameters supported by these modules, please consult the following URL: https://docs.Ansible.com/Ansible/latest/modules/ios_interface_module.html