In the previous video, we have done create a script to configure multiple router at once using netmiko. 2
But if we see here, the configuration is still manual, 3
so we type the configuration for loopback0 and loopback1. 4
In this case, we just create 2 loopback, the question is, how if we need to configure 5
5 loopback? This is not efficient if we configure the loopback one by one like this. 6
The solution is, we can use looping. 7
So now we are going to learn nested looping, which is looping inside looping. 8
The first looping is looping to the router, 9
and then, for each router, we will looping to create multiple loopback interface. 10
Let’s just start. Let’s say we will create loopback 3 until 6. 11
Let’s copy this script, create new file, let’s say the name is netmiko_looping_nested.py, 12
And then paste the script. 13
Here we looping to the router, 14
connect to the router, and the here we have list config to configure loopback0 and loopback 1. 15
we will change this list to configure loopback 3 until 6, or actually we don’t have loopback2 yet, 16
so let’s configure loopback2 until 5. 17
Let’s just remove this, 18
so now the list is empty, 19
And then here we can define a looping, for x in range 2 until 6, so here we looping from 2 to 5. 20
And then here list_config.append, 21
interface loopback, here we need to use f string, and here we can use x. 22
List_config.append, here we use f string again, ip address 10. 23
If you remember, the ip address of loopback0 is 10.1.1, the ip address of loopback1 is 10.2.2, 24
So this 2 number is the loopback number increment by 1, so here we can use x + 1, 25
and then the last number will be based on the router number. 26
So here we can use n. 27
Okay we have done here 28
This append is used to add an item to the list, 29
Here the list is empty, and then we do looping from 2 to 5, and then we add the command 30
to create interface loopback and configure the ip address of interface loopback to the list. 31
Oh ya, don’t forget to define the subnetmask here. 32
Let’s try to print the list_config, this is optional. 33
Save, let’s back to the terminal, ls, here we can see that we have netmiko_looping_nested.py, 34
let’s execute this script. 35
Here we can see the list config, interface loopback2, 36
the ip address is 10.3.3.1 255.255.255.255, loopback3, the ip address is 10.4.4.1, and others. 37
Here we can see that the command is sent to the router1, 38
Router 2 success, 39
Router 3 success, 40
Router 4 success, and router 5 also success. 41
Okay so now we are success to configure multiple interface on all router at once. 42
I think enough for this video 43
Thankyou for watching and see you on the next video.