Looking for a Tool to Create Device Configurations from Templates

One of my readers sent me this question:

Other than using Excel (and of course an automation tool) any suggestions for a tool to create device config for some 200 customer VRFs from a standard template?

You need three things to get the job done:

  • Data (what values you want to have in each configuration)
  • Templating tool and configuration templates
  • Some glue that connects the two and generates the configurations.

You can store data in text files (CSV or YAML), Excel spreadsheets, or a database (any database would do, but object-oriented databases might be a better fit than relational ones).

However, when selecting a potential data store, keep in mind that (as I explained in the Data Stores part of the Data Model section in my Building Network Automation Solutions course) you have to:

  • Have a tool to update the data, and while databases have numerous interesting properties, its way easier to use Notepad, Sublime Text or Excel to update the data;
  • Have a mechanism to track changes to the data, and a Git repository is way simpler to implement than any alternative.

Next you need a templating tool. Every programming language has one, and as Python is the new black, you might want to go with Jinja2.

Finally, you need some glue that will take device-specific data, push it through a template, and save the results in a file. Writing a Python script to do that is really easy (unless it’s your first script).

However, the moment you have a tool, you want a more powerful tool. For example, you might want to have global parameters, or groups of devices, or push configurations to the devices, or… and this is where Ansible starts making perfect sense for a minimum investment in tools and programming.

There are people who prefer to do the undifferentiated heavy lifting, and then there are the lazy people (like myself) who like to use the tools that are out there, and once I got familiar with YAML/Jinja2/Ansible combo I wouldn't even think about writing my own Python script to get the job done, but that's just me.

Sounds interesting? Why don’t you explore the Ansible for Networking Engineers webinar, and once you get interested in writing real-life solutions join the Building Network Automation Solutions course?

8 comments:

  1. The other great thing about the YAML/Jinja2/Ansible combination is that once you have it, it is just a quick'switch'to dry-run and push to the device with junos-config or the equivalent for your vendor.
  2. Apologies, you had actually already made that point. Templating is the "gateway drug" to full Ansible automation though, in my opinion.
  3. A few months back I talked to our implementation engineers if they did any Ansible or Python templating when rolling out Nexus configs to clients. The answer was no but they used an Excel spreadsheet and some other program that somehow pulled the data out of the spreadsheet to insert in a template. The problem is that there was a ton of manual fixing of the script they had to do afterwards.

    Enter Ansible and the "xls_to_facts" module I found. Since spreadsheets were already a familiar data store, I stuck with that. I created tabs for various features (global config items, AAA, users, VLANs, VRFs, etc.) then wrote the Jinja to insert the data if it was defined in the spreadsheet, otherwise skip that section of the script. You could keep it as simple as needed or define a lot of stuff.
    Replies
    1. Thanks a million! It's so nice to learn something new every time I publish a blog post ;))
  4. sometimes I use this webapp 8config.com founded through reddit, seems new. Nice for snippets but don't scale.
  5. We implemented automation for our systems (100-800 devices are controlled this way) more than 10 years ago. At that time we decided to store data in xml files, use apache velocity template language (funny?) and glue them using java-based GUI.
    Customer express what he/she wants to change in the system (add new system components - not router or switch!) and this request through the GUI sparks actions. As a consequence many networking devices are configured using templates to fullfil the system change required by the Customer.

    It's another use of automation implemented many years ago.

    Side note: automation has been always used in big vendors testing labs - I spent more than 12 years in such environments where hundreds of devices are configured at once.
  6. Enter... microsoft word mailings feature
  7. I've been using confplate with csv files and found it very useful for any config task that needs to be done more than once. It is python based and uses jinja2 templates.
    https://github.com/verbosemode/confplate
Add comment
Sidebar