Network Automation with Ansible – Part 3 – Generating Device Configuration with Jinja2 Templates

In this example I generated configuration for two switches, where I configured few VLANs and their interfaces and some DHCP Pools.

Jinja2 Template

I am using Jinja2 templating module to generate the configuration. I am using a tree structure of directory and files to pass the configuration commands and variable required to generate the configuration. I create a role named switch which I called in my playbook.

The directories are structured as

Role – Switch

Playbook

Playbook

Task/main.yml

Task

Templates/switch. j2

Template

Vars/main.yml

Variables

Sample Configuration Generated by Playbook, Template and Variables

I generated configuration for two switches, as I passed the variables for two switches.

Switch 1

Configuration – Switch 1

Switch 2

Configuration – Switch2

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.