cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
691
Views
3
Helpful
3
Replies

Best way to create golden configs with Python/Jinja2?

Josh Morris
Level 3
Level 3

I would like to create a Python job using Jinja2 templates to create golden configs. This is easy enough, but my question is should I use one large template for the entirety of the config or split it into multiple templates (base, snmp, ntp, aaa, etc). I ask for a few reasons...

  • I would like a single job for multiple switch types with require different interface syntax.
  • If I wanted to do something like add a new SNMP account, having the config ready in a snippet just for SNMP would save time without having to generate a complete config. 
  • I would eventually like to migrate to Ansible and I feel like having the sections already split would help that transition. 

Any other Python method I should consider here? Thanks. 

1 Accepted Solution

Accepted Solutions

This was always my preferred way. We use to split the j2 files into areas such as security (ACL for example) BGP to providers, BGP to peerings etc, we had a bare base config too such as mgmt ip and usernames. You are right imo, managing one large j2 file and having this as your source of truth with what would be many changes per day and lets face it some of our running-configs get huge, smaller changes work much better.

Hope this helps.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

View solution in original post

3 Replies 3

This was always my preferred way. We use to split the j2 files into areas such as security (ACL for example) BGP to providers, BGP to peerings etc, we had a bare base config too such as mgmt ip and usernames. You are right imo, managing one large j2 file and having this as your source of truth with what would be many changes per day and lets face it some of our running-configs get huge, smaller changes work much better.

Hope this helps.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

It does, thanks. So each config section is its own j2 template, then the python takes the variable input and combines all the j2 templates into one large template to be put on a switch?

Yes sir, this is the way. I think i had an example with Napalm here back in the day as a jinja helper https://github.com/CiscoDevNet/learning_lab_napalm_code/blob/master/jinja_helper.py

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: