{"id":135,"date":"2019-07-10T11:41:16","date_gmt":"2019-07-10T03:41:16","guid":{"rendered":"http:\/\/mayanknauni.com\/?p=135"},"modified":"2019-07-10T11:42:39","modified_gmt":"2019-07-10T03:42:39","slug":"network-automation-with-ansible-part-3-generating-device-configuration-with-jinja2-templates","status":"publish","type":"post","link":"https:\/\/mayanknauni.com\/?p=135","title":{"rendered":"Network Automation with Ansible &#8211; Part 3 &#8211; Generating Device Configuration with Jinja2 Templates"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">In this example I generated configuration for two switches, where I configured few VLANs and their interfaces and some DHCP Pools.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Jinja2 Template<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">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 <strong><em>switch<\/em><\/strong> which I called in my playbook.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"> <strong><em>The directories are structured as<\/em><\/strong> <\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1253\" height=\"795\" src=\"https:\/\/i1.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/tree-structure.png?fit=604%2C383&amp;ssl=1\" alt=\"\" class=\"wp-image-138\" srcset=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/tree-structure.png?w=1253&amp;ssl=1 1253w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/tree-structure.png?resize=300%2C190&amp;ssl=1 300w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/tree-structure.png?resize=768%2C487&amp;ssl=1 768w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/tree-structure.png?resize=1024%2C650&amp;ssl=1 1024w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption><em>Role &#8211; Switch<\/em><br><\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Playbook<\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1376\" height=\"604\" src=\"https:\/\/i2.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Playbook.png?fit=604%2C265&amp;ssl=1\" alt=\"\" class=\"wp-image-139\" srcset=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Playbook.png?w=1376&amp;ssl=1 1376w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Playbook.png?resize=300%2C132&amp;ssl=1 300w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Playbook.png?resize=768%2C337&amp;ssl=1 768w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Playbook.png?resize=1024%2C449&amp;ssl=1 1024w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption><em>Playbook<\/em><br><\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><em>Task\/main.yml<\/em><\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1819\" height=\"366\" src=\"https:\/\/i1.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Task.png?fit=604%2C122&amp;ssl=1\" alt=\"\" class=\"wp-image-140\" srcset=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Task.png?w=1819&amp;ssl=1 1819w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Task.png?resize=300%2C60&amp;ssl=1 300w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Task.png?resize=768%2C155&amp;ssl=1 768w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Task.png?resize=1024%2C206&amp;ssl=1 1024w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption><em>Task<\/em><br><\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><em>Templates\/switch. j2<\/em><\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1340\" height=\"1036\" src=\"https:\/\/i1.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Template.png?fit=604%2C467&amp;ssl=1\" alt=\"\" class=\"wp-image-141\" srcset=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Template.png?w=1340&amp;ssl=1 1340w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Template.png?resize=300%2C232&amp;ssl=1 300w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Template.png?resize=768%2C594&amp;ssl=1 768w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Template.png?resize=1024%2C792&amp;ssl=1 1024w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption><em>Template<\/em><br><\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><em>Vars\/main.yml<\/em><\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1734\" height=\"666\" src=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Variables.png?fit=604%2C232&amp;ssl=1\" alt=\"\" class=\"wp-image-142\" srcset=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Variables.png?w=1734&amp;ssl=1 1734w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Variables.png?resize=300%2C115&amp;ssl=1 300w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Variables.png?resize=768%2C295&amp;ssl=1 768w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Variables.png?resize=1024%2C393&amp;ssl=1 1024w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption><em>Variables<\/em><br><\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><em>Sample Configuration Generated by Playbook, Template and Variables<\/em><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">I generated configuration for two switches, as I passed the variables for two switches.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Switch 1<\/em><\/strong><br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"797\" height=\"932\" src=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Configuration-Switch1.png?resize=797%2C932&#038;ssl=1\" alt=\"\" class=\"wp-image-143\" srcset=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Configuration-Switch1.png?w=797&amp;ssl=1 797w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Configuration-Switch1.png?resize=257%2C300&amp;ssl=1 257w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Configuration-Switch1.png?resize=768%2C898&amp;ssl=1 768w\" sizes=\"auto, (max-width: 797px) 100vw, 797px\" \/><figcaption><em>Configuration &#8211; Switch 1<\/em><br><\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Switch 2<\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"752\" height=\"951\" src=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Configuration-Switch2.png?resize=752%2C951&#038;ssl=1\" alt=\"\" class=\"wp-image-144\" srcset=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Configuration-Switch2.png?w=752&amp;ssl=1 752w, https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/Configuration-Switch2.png?resize=237%2C300&amp;ssl=1 237w\" sizes=\"auto, (max-width: 752px) 100vw, 752px\" \/><figcaption><em>Configuration &#8211; Switch2<\/em><br><\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[4],"tags":[],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-netdevops"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"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.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Abhay Kranwal\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/mayanknauni.com\/?p=135\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Cloud Whisperer \u2013 Taming the Digital Dragon\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Network Automation with Ansible \u2013 Part 3 \u2013 Generating Device Configuration with Jinja2 Templates Cloud Whisperer\" \/>\n\t\t<meta property=\"og:description\" content=\"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.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mayanknauni.com\/?p=135\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2023\/08\/cropped-cropped-Blue-and-Green-Modern-Technology-Logo.png?fit=333%2C342&#038;ssl=1\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2023\/08\/cropped-cropped-Blue-and-Green-Modern-Technology-Logo.png?fit=333%2C342&#038;ssl=1\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-07-10T03:41:16+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-07-10T03:42:39+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Network Automation with Ansible \u2013 Part 3 \u2013 Generating Device Configuration with Jinja2 Templates Cloud Whisperer\" \/>\n\t\t<meta name=\"twitter:description\" content=\"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.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2023\/08\/cropped-cropped-Blue-and-Green-Modern-Technology-Logo.png?fit=333%2C342&amp;ssl=1\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135#blogposting\",\"name\":\"Network Automation with Ansible \\u2013 Part 3 \\u2013 Generating Device Configuration with Jinja2 Templates Cloud Whisperer\",\"headline\":\"Network Automation with Ansible &#8211; Part 3 &#8211; Generating Device Configuration with Jinja2 Templates\",\"author\":{\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?author=2#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i1.wp.com\\\/mayanknauni.com\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/tree-structure.png?fit=604%2C383&amp;ssl=1\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135\\\/#articleImage\"},\"datePublished\":\"2019-07-10T11:41:16+08:00\",\"dateModified\":\"2019-07-10T11:42:39+08:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135#webpage\"},\"articleSection\":\"NetDevOps\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mayanknauni.com#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mayanknauni.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?cat=4#listItem\",\"name\":\"NetDevOps\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?cat=4#listItem\",\"position\":2,\"name\":\"NetDevOps\",\"item\":\"https:\\\/\\\/mayanknauni.com\\\/?cat=4\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135#listItem\",\"name\":\"Network Automation with Ansible &#8211; Part 3 &#8211; Generating Device Configuration with Jinja2 Templates\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mayanknauni.com#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135#listItem\",\"position\":3,\"name\":\"Network Automation with Ansible &#8211; Part 3 &#8211; Generating Device Configuration with Jinja2 Templates\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?cat=4#listItem\",\"name\":\"NetDevOps\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/#person\",\"name\":\"Mayank Nauni\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135#personImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8adb58e2795dfce95a74d7fd72c38f682f8514e4545ad8099e86a0a34d736417?s=96&r=g\",\"width\":96,\"height\":96,\"caption\":\"Mayank Nauni\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?author=2#author\",\"url\":\"https:\\\/\\\/mayanknauni.com\\\/?author=2\",\"name\":\"Abhay Kranwal\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0247e6ad33f9679b8870c8291916b105dbdf3eefbe42e3e2991fd64e39240e41?s=96&r=g\",\"width\":96,\"height\":96,\"caption\":\"Abhay Kranwal\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135#webpage\",\"url\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135\",\"name\":\"Network Automation with Ansible \\u2013 Part 3 \\u2013 Generating Device Configuration with Jinja2 Templates Cloud Whisperer\",\"description\":\"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.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?p=135#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?author=2#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/?author=2#author\"},\"datePublished\":\"2019-07-10T11:41:16+08:00\",\"dateModified\":\"2019-07-10T11:42:39+08:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/#website\",\"url\":\"https:\\\/\\\/mayanknauni.com\\\/\",\"name\":\"Cloud Whisperer\",\"description\":\"Taming the Digital Dragon\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mayanknauni.com\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Network Automation with Ansible \u2013 Part 3 \u2013 Generating Device Configuration with Jinja2 Templates Cloud Whisperer","description":"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.","canonical_url":"https:\/\/mayanknauni.com\/?p=135","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/mayanknauni.com\/?p=135#blogposting","name":"Network Automation with Ansible \u2013 Part 3 \u2013 Generating Device Configuration with Jinja2 Templates Cloud Whisperer","headline":"Network Automation with Ansible &#8211; Part 3 &#8211; Generating Device Configuration with Jinja2 Templates","author":{"@id":"https:\/\/mayanknauni.com\/?author=2#author"},"publisher":{"@id":"https:\/\/mayanknauni.com\/#person"},"image":{"@type":"ImageObject","url":"https:\/\/i1.wp.com\/mayanknauni.com\/wp-content\/uploads\/2019\/07\/tree-structure.png?fit=604%2C383&amp;ssl=1","@id":"https:\/\/mayanknauni.com\/?p=135\/#articleImage"},"datePublished":"2019-07-10T11:41:16+08:00","dateModified":"2019-07-10T11:42:39+08:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/mayanknauni.com\/?p=135#webpage"},"isPartOf":{"@id":"https:\/\/mayanknauni.com\/?p=135#webpage"},"articleSection":"NetDevOps"},{"@type":"BreadcrumbList","@id":"https:\/\/mayanknauni.com\/?p=135#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mayanknauni.com#listItem","position":1,"name":"Home","item":"https:\/\/mayanknauni.com","nextItem":{"@type":"ListItem","@id":"https:\/\/mayanknauni.com\/?cat=4#listItem","name":"NetDevOps"}},{"@type":"ListItem","@id":"https:\/\/mayanknauni.com\/?cat=4#listItem","position":2,"name":"NetDevOps","item":"https:\/\/mayanknauni.com\/?cat=4","nextItem":{"@type":"ListItem","@id":"https:\/\/mayanknauni.com\/?p=135#listItem","name":"Network Automation with Ansible &#8211; Part 3 &#8211; Generating Device Configuration with Jinja2 Templates"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mayanknauni.com#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mayanknauni.com\/?p=135#listItem","position":3,"name":"Network Automation with Ansible &#8211; Part 3 &#8211; Generating Device Configuration with Jinja2 Templates","previousItem":{"@type":"ListItem","@id":"https:\/\/mayanknauni.com\/?cat=4#listItem","name":"NetDevOps"}}]},{"@type":"Person","@id":"https:\/\/mayanknauni.com\/#person","name":"Mayank Nauni","image":{"@type":"ImageObject","@id":"https:\/\/mayanknauni.com\/?p=135#personImage","url":"https:\/\/secure.gravatar.com\/avatar\/8adb58e2795dfce95a74d7fd72c38f682f8514e4545ad8099e86a0a34d736417?s=96&r=g","width":96,"height":96,"caption":"Mayank Nauni"}},{"@type":"Person","@id":"https:\/\/mayanknauni.com\/?author=2#author","url":"https:\/\/mayanknauni.com\/?author=2","name":"Abhay Kranwal","image":{"@type":"ImageObject","@id":"https:\/\/mayanknauni.com\/?p=135#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/0247e6ad33f9679b8870c8291916b105dbdf3eefbe42e3e2991fd64e39240e41?s=96&r=g","width":96,"height":96,"caption":"Abhay Kranwal"}},{"@type":"WebPage","@id":"https:\/\/mayanknauni.com\/?p=135#webpage","url":"https:\/\/mayanknauni.com\/?p=135","name":"Network Automation with Ansible \u2013 Part 3 \u2013 Generating Device Configuration with Jinja2 Templates Cloud Whisperer","description":"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.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mayanknauni.com\/#website"},"breadcrumb":{"@id":"https:\/\/mayanknauni.com\/?p=135#breadcrumblist"},"author":{"@id":"https:\/\/mayanknauni.com\/?author=2#author"},"creator":{"@id":"https:\/\/mayanknauni.com\/?author=2#author"},"datePublished":"2019-07-10T11:41:16+08:00","dateModified":"2019-07-10T11:42:39+08:00"},{"@type":"WebSite","@id":"https:\/\/mayanknauni.com\/#website","url":"https:\/\/mayanknauni.com\/","name":"Cloud Whisperer","description":"Taming the Digital Dragon","inLanguage":"en-US","publisher":{"@id":"https:\/\/mayanknauni.com\/#person"}}]},"og:locale":"en_US","og:site_name":"Cloud Whisperer \u2013 Taming the Digital Dragon","og:type":"article","og:title":"Network Automation with Ansible \u2013 Part 3 \u2013 Generating Device Configuration with Jinja2 Templates Cloud Whisperer","og:description":"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.","og:url":"https:\/\/mayanknauni.com\/?p=135","og:image":"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2023\/08\/cropped-cropped-Blue-and-Green-Modern-Technology-Logo.png?fit=333%2C342&#038;ssl=1","og:image:secure_url":"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2023\/08\/cropped-cropped-Blue-and-Green-Modern-Technology-Logo.png?fit=333%2C342&#038;ssl=1","article:published_time":"2019-07-10T03:41:16+00:00","article:modified_time":"2019-07-10T03:42:39+00:00","twitter:card":"summary_large_image","twitter:title":"Network Automation with Ansible \u2013 Part 3 \u2013 Generating Device Configuration with Jinja2 Templates Cloud Whisperer","twitter:description":"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.","twitter:image":"https:\/\/i0.wp.com\/mayanknauni.com\/wp-content\/uploads\/2023\/08\/cropped-cropped-Blue-and-Green-Modern-Technology-Logo.png?fit=333%2C342&ssl=1"},"aioseo_meta_data":{"post_id":"135","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2023-04-28 04:21:49","updated":"2025-08-04 08:28:59","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/mayanknauni.com\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/mayanknauni.com\/?cat=4\" title=\"NetDevOps\">NetDevOps<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tNetwork Automation with Ansible \u2013 Part 3 \u2013 Generating Device Configuration with Jinja2 Templates\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/mayanknauni.com"},{"label":"NetDevOps","link":"https:\/\/mayanknauni.com\/?cat=4"},{"label":"Network Automation with Ansible &#8211; Part 3 &#8211; Generating Device Configuration with Jinja2 Templates","link":"https:\/\/mayanknauni.com\/?p=135"}],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mayanknauni.com\/index.php?rest_route=\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mayanknauni.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mayanknauni.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mayanknauni.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mayanknauni.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=135"}],"version-history":[{"count":3,"href":"https:\/\/mayanknauni.com\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions"}],"predecessor-version":[{"id":147,"href":"https:\/\/mayanknauni.com\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions\/147"}],"wp:attachment":[{"href":"https:\/\/mayanknauni.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mayanknauni.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mayanknauni.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}