Friday, October 25, 2019

Jinja2 templating - best way to pass variables to template?

I'm beginning my journey of templating configurations with Jinja2 and Python3. Hey, it's not so hard after all! Even a dummy like me can do it. I ended up following the guide below to get started:

https://blogs.cisco.com/developer/network-configuration-template

However Cisco recommended to pass each variable individually, which is a nightmare if you have more than... one variable. So I began passing in dictionaries with keys and values, which reduced my variables to pass down to just one. I've seen some other examples using .csv files as well, which seems great for large scale deployments.

I'd like to ask what others are doing in their networks to generate configs with Jinja2. How do you keep your variables? Dictionaries? Spreadsheets? Some other magic?

At this point I'm not quite using for loops in my templates, but would like to. Something like:

https://realpython.com/primer-on-jinja-templating/



No comments:

Post a Comment