Configs Templates Take 1 (15 of 30)

I have developed several config template systems over the years, so I wanted to write a tutorial on some of the things I have done. This first tutorial is not much more than going over HTML::Template cpan module, and having an input form, with a short demo and providing the script. As I build on each one, it will get more and more complicated. You can see a much more in depth coverage at packetlife, but this is meant to be much more step-by-step.

The basic way this works is by creating a template file that has variables in it (e.g. <TMPL_VAR NAME=HOSTNAME>.) You populate a standard HTML FORM, output that form to a perl script that does the HTML::Template find/replace like feature.

Here is a quick example of how you populate the variables:

1
2
3
4
5
6
7
8
snmp-server community <TMPL_VAR NAME=SNMPRO> RO 10
snmp-server community <TMPL_VAR NAME=SNMPRW> RW 11
snmp-server host 10.10.179.254 trap <TMPL_VAR NAME=SNMPRO>
snmp-server enable traps
snmp-server contact <TMPL_VAR NAME=SNMPCONTACT>
tacacs-server host 10.10.179.248
tacacs-server host 10.10.179.249
tacacs-server key <TMPL_VAR NAME=VLAN>

Then you can build a simple form:

html_form

And you will get your output:

template_output

Please ensure you have correct CGI permissions on your directory, that the file final.pl is executable and that you have the two cpan modules HTML::Template and CGI.

Probably not the most exciting system, but you can see how this is the foundation to build on. Most configurations are very similar.

You can see this in action here: and see the file script on my Github.

 

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>