Scrapli and Flask – Part 6: Base Config Device Templates

I have added the ability to create a base device template for Cisco IOS, Nexus and IOS-XE.
The idea of this is to create a quick way to get a basic configuration to SSH on to the device.
For switches, the options for configuration can become quite complex as you can have either a VLAN or a physical interface and then there is the trunking of that VLAN, port channels etc. If this was an organisation it would specify the standard for this type of config.

I have left the base config quite basic and using VLAN1, which is ok for me and my labs!
My aim is to make setting up a GNS3 lab quicker.

Code for the this current version2 can be found in GitHub

Below is an example of a new IOS router. The template output is pasted into the device giving SSH access and allowing the device to be added to the device inventory.

Add mcastR2 to device inventory, using the base template for SSH connectivity

Making the Template Page

This was quite a simple process. Mostly a copy and paste from what I already had. The part that caused me the most problems was creating the config to be neatly output on the the HTML page. If I used a single string it would be one line. I have put a multi line string on and the variables using fstrings. This looks quite readable.
The string is then split on each new line and added to a list. This list is passed into the HTML template and output line by line in a readable code format.

HTML Output Page

This page does show the password. Not exacly ideal, but the password must be shown in plaintext to be pasted into the device. The only way around this is to use hashed passwords. This can easily be done. But not something I have bothered with in the lab. I would jsut need to change the enable password 0 to 4,5,7,8,9 – depending on the version.

Leave a Comment

Your email address will not be published. Required fields are marked *