Using TCL to Prepare Configuration

If you have worked as a network engineer for an enterprise or even a telco, you would notice that the best practice to have a standard configuration template. Sometimes, you are stuck in a situation wherein you need to prepare configuration let's say for around 20 routers and time is not on your side. My approach for this when I was starting my networking career was to get that standard template and start filing up the necessary configuration in notepad for the 20 routers and save one file after another. Believe me it was not an easy task and it was prone to having typo's.

It is for sure a tedious task but using TCL, it will pretty much make your life easier. I have researched for a way to automate the config preparation provided you have all the necessary data required. I am not a programmer but somehow I managed to find some TCL software and commands to make this possible. Before we begin we would need to have TCLKIT which can be downloaded here.

Now for this example, let us only try to create configs for 10 routers. Our standard config is as shown below. (not so long so make things easier)


hostname (hostname)
!
interface Serial1/1
ip address (ip address)(mask)
!
router ospf 1
network (network) (wildcard) area (ospf area)


The first step is to create our variables, quite much work required for this especially for long standard configs. We will create variables for those with () in the standard config above. These are the parts in the configuration wherein the data will be placed. Standard configuration with variables shown below.


hostname $hostname
!
interface Serial1/1
ip address $ipaddress $ipmask
!
router ospf 1
network $network $wildcard area $ospfarea

Now we have created our variables. Let us use the multivariable "foreach" TCL command to create a looping script. We put in our variables next to the "foreach" statement. The "$" is not required. If you are not familiar with this, please visit this post.


foreach {hostname ipaddress ipmask network wildcard ospfarea}

The next line of this script will now contain the data. Prepare the data in excel spreadsheet and the sequence of the columns should be the same as the one listed in the "foreach" statement. Then add that to the second line of the script. Put an open { before the data and } after the data.
Add also the important commands below that will make auto text file generation for each config file. The final script will look like something below. Then save this as a text file.


foreach {hostname ipaddress ipmask network wildcard ospfarea} {

Router1 1.1.1.1 255.255.255.0 1.1.1.1 0.0.0.0 1
Router2 1.1.1.2 255.255.255.0 1.1.1.2 0.0.0.0 2
Router3 1.1.1.3 255.255.255.0 1.1.1.3 0.0.0.0 3
Router4 1.1.1.4 255.255.255.0 1.1.1.4 0.0.0.0 4
Router5 1.1.1.5 255.255.255.0 1.1.1.5 0.0.0.0 5
Router6 1.1.1.6 255.255.255.0 1.1.1.6 0.0.0.0 6
Router7 1.1.1.7 255.255.255.0 1.1.1.7 0.0.0.0 7
Router8 1.1.1.8 255.255.255.0 1.1.1.8 0.0.0.0 8
Router9 1.1.1.9 255.255.255.0 1.1.1.9 0.0.0.0 9
Router10 1.1.1.10 255.255.255.0 1.1.1.10 0.0.0.0 10

} {set data "

hostname $hostname
!
interface Serial1/1
ip address $ipaddress $ipmask
!
router ospf 1
network $network $wildcard area $ospfarea

"
set filename "${hostname}.txt"
set fileId [open $filename "w"]
puts -nonewline $fileId $data
close $fileId

}

Now its time to auto generate the configs. What this looping script does is take the first line on the data, do the variable substitution and then at the end it will save the text file with the hostname as the filename. It does this until the last line of the data. The files will be auto generated where the TCLKIT software is saved.




Open TCLKIT, two windows will appear big and small. Click on File -> Source ->Go to the directory where you saved the script as text file -> Change "Files of Type to "All Files" -> Select the Script. Then viola, your configurations appear and all variables substituted. It makes life easier for a network engineer.





Comments

10 Responses to "Using TCL to Prepare Configuration"

isinformer@gmail.com said... March 15, 2011 at 11:19 AM

very informative! Can you mention some other similar tools which you might have stumbled upon.

rakesh.mandava@gmail.com said... April 12, 2011 at 9:00 PM

very well written article,Thx.Pls share more scripts of this kind.Is there any graphical way to do the similar task ? what is your opinion abt perl ?

Steven Vu said... May 26, 2011 at 9:21 AM

Hello, What is your contact?

Pete said... May 26, 2011 at 9:37 AM

Livin4jc@gmail.com why?

Junier said... November 29, 2012 at 8:01 PM

This is cool my fried

phyo phyohein said... March 1, 2013 at 3:31 PM

I have read your blog since 2010. Actually you are my teacher. I learned a lot from your blog. Really really thanks and I really respect and appreciate your work. I respected you since 2010.You are my fan since 2010.:)

Anonymous said... March 3, 2013 at 1:45 AM
This comment has been removed by a blog administrator.
networking dummies said... May 10, 2013 at 5:49 PM

tcl is usefull for made easy dor this

Aaron paul said... May 30, 2013 at 6:05 PM

Thanks for sharing this informative information. I really liked this blog post.Network configuration is really very hard for a big organization only a ccna, ccnp, ccie certified person can handle this. because they have vast experience of working on Network devices and know how they have to configure them.
____________
CCIE Service Provider

John Peter said... June 1, 2013 at 3:31 PM

That really is the solution to the problem. Thanks for your thoughts. Cisco Training

Post a Comment

Certifications

Certifications

The Dreamer

A fun loving person who enjoys learning new things. Currently working as a Network Engineer supporting the global network of a Fortune 500 company. This blog serves as my notes for the labs I created for my CCIE journey. I can guarantee there are errors in my posts. If you spot them, please let me know.

Join my Facebook Page I WANT TO BE A CCIE

Donate to the Cause

My aim is to create materials for free and possibly a free lab. If you wish to help out, please send any amount. Thanks.

Join my Bandwagon

Blogs that I Read