Python – Script12: Configure Multiple Devices Interfaces config file via SSH (Netmiko)

Step1: Configure file with all interface details
	nano iosv_l2_access
Vlan 2
int range g2/0 – 3
switchport mode access
switchport access vlan 2
int range g0/0 – 3
switchport trunk encapsulation dot1q
switchport mode trunk
switchport nonegotiate
switchport trunk allowed vlan1,2
Step2: Configure file with for python script
	nano int_config_netmiko.py
from netmiko import ConnectHandler
 
iosv_l2_s1 = {
    ‘device_type’: ‘cisco_ios’,
    ‘ip’: ‘192.168.10.21’,
    ‘username’: ‘rachit’,
    ‘password’: ‘cisco’,
    ‘secret’: ‘cisco’
}
 
iosv_l2_s2 = {
    ‘device_type’: ‘cisco_ios’,
    ‘ip’: ‘192.168.10.22’,
    ‘username’: ‘rachit’,
    ‘password’: ‘cisco’,
    ‘secret’: ‘cisco’
}
 
iosv_l2_s3 = {
    ‘device_type’: ‘cisco_ios’,
    ‘ip’: ‘192.168.10.23’,
    ‘username’: ‘rachit’,
    ‘password’: ‘cisco’,
    ‘secret’: ‘cisco’
}
 
with open(‘iosv_l2_access’) as f:
    lines = f.read().splitlines()
print lines
 
all_devices = [iosv_l2_s1, iosv_l2_s2, iosv_l2_s3]
 
for devices in all_devices:
    net_connect = ConnectHandler(**devices)
    net_connect.enable()
    output = net_connect.send_config_set(lines)
    print output

Network Architect | CCIEx3 #29824 JNCIE #2197 VCIX-NV

Leave a Comment