{"id":3415,"date":"2025-02-13T22:45:08","date_gmt":"2025-02-13T22:45:08","guid":{"rendered":"https:\/\/technobabble.us.to\/?p=3415"},"modified":"2025-02-13T23:36:48","modified_gmt":"2025-02-13T23:36:48","slug":"infrastructure-as-code-using-netbox-and-jinja2-to-build-zero-touch-provisioning-for-sonic-switches","status":"publish","type":"post","link":"https:\/\/technobabble.us.to\/?p=3415","title":{"rendered":"Infrastructure as Code: Using NetBox and Jinja2 to build Zero Touch Provisioning for SONiC switches"},"content":{"rendered":"\n<p>When I was hired at eBay one of the first tasks I was given was to find an easy way to swap switches within a rack to help facilitate testing of various SONiC platforms. I knew this as ZTP from my years as a network engineer but I was not sure how it was all going to work considering the Hardware Engineering team had no automation at the time with regards to infrastructure. They were still working off spreadsheets and wiki pages, all manually updated. <\/p>\n\n\n\n<p>The first step to realize the goal of ZTP required a &#8220;Source of Truth&#8221; for all of the assets in the hardware lab. Luckily I had just watched a NANOG video that talked about the open source tool called NetBox. I setup NetBox in my first week and started the process of adding in all of the lab assets. At first we entered a lot of stuff by hand but quickly all of the info was collected via python automation using Nornir and Netmiko. Nornir is a python automation framework with plugins for NetBox that greatly simplifies the process of connecting to various devices within the infrastructure. <\/p>\n\n\n\n<p>Zero Touch Provisioning is simply automating the configuration and deployment of an end device like a network switch. There are several steps in the process but one critical piece is building the configurations. If you have several of the same devices in your infrastructure your configs will have a static portion that is the same across all devices and a dynamic portion that is unique to each device. I will be showing off how I built the dynamic portions of the configuration using Infrastructure as Code concepts achieved with open sources tools like NetBox and the Jinja2 template language.<\/p>\n\n\n\n<p>Dynamic &#8220;interface&#8221; section of the SONiC switch configuration using Jinja2   <\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.05.59.png\"><img loading=\"lazy\" decoding=\"async\" width=\"2082\" height=\"296\" data-id=\"3423\" src=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.05.59.png\" alt=\"\" class=\"wp-image-3423\" srcset=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.05.59.png 2082w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.05.59-300x43.png 300w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.05.59-768x109.png 768w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.05.59-1536x218.png 1536w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.05.59-2048x291.png 2048w\" sizes=\"auto, (max-width: 2082px) 100vw, 2082px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Final rendered dynamic interface configuration for the SONiC switch <\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.07.16.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1578\" height=\"266\" data-id=\"3425\" src=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.07.16.png\" alt=\"\" class=\"wp-image-3425\" srcset=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.07.16.png 1578w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.07.16-300x51.png 300w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.07.16-768x129.png 768w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.07.16-1536x259.png 1536w\" sizes=\"auto, (max-width: 1578px) 100vw, 1578px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Dynamic &#8220;port&#8221; section of the SONiC switch configuration using Jinja2<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.11.58.png\"><img loading=\"lazy\" decoding=\"async\" width=\"2072\" height=\"696\" data-id=\"3431\" src=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.11.58.png\" alt=\"\" class=\"wp-image-3431\" srcset=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.11.58.png 2072w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.11.58-300x101.png 300w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.11.58-768x258.png 768w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.11.58-1536x516.png 1536w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.11.58-2048x688.png 2048w\" sizes=\"auto, (max-width: 2072px) 100vw, 2072px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Final rendered dynamic port configuration for the SONiC switch 10G, 25G,100G &amp; 400G ports<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-4 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.34.08.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1296\" height=\"918\" data-id=\"3446\" src=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.34.08.png\" alt=\"\" class=\"wp-image-3446\" srcset=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.34.08.png 1296w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.34.08-300x213.png 300w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.34.08-768x544.png 768w\" sizes=\"auto, (max-width: 1296px) 100vw, 1296px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-5 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.35.11.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1410\" height=\"912\" data-id=\"3448\" src=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.35.11.png\" alt=\"\" class=\"wp-image-3448\" srcset=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.35.11.png 1410w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.35.11-300x194.png 300w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.35.11-768x497.png 768w\" sizes=\"auto, (max-width: 1410px) 100vw, 1410px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-6 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.36.01.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1348\" height=\"910\" data-id=\"3451\" src=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.36.01.png\" alt=\"\" class=\"wp-image-3451\" srcset=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.36.01.png 1348w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.36.01-300x203.png 300w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.36.01-768x518.png 768w\" sizes=\"auto, (max-width: 1348px) 100vw, 1348px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-7 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.36.34.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1720\" height=\"880\" data-id=\"3453\" src=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.36.34.png\" alt=\"\" class=\"wp-image-3453\" srcset=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.36.34.png 1720w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.36.34-300x153.png 300w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.36.34-768x393.png 768w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.36.34-1536x786.png 1536w\" sizes=\"auto, (max-width: 1720px) 100vw, 1720px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Dynamic &#8220;VLAN&#8221; section of the SONiC switch configuration using Jinja2<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-8 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.19.50.png\"><img loading=\"lazy\" decoding=\"async\" width=\"2092\" height=\"918\" data-id=\"3440\" src=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.19.50.png\" alt=\"\" class=\"wp-image-3440\" srcset=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.19.50.png 2092w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.19.50-300x132.png 300w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.19.50-768x337.png 768w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.19.50-1536x674.png 1536w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.19.50-2048x899.png 2048w\" sizes=\"auto, (max-width: 2092px) 100vw, 2092px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Final rendered dynamic vlan configuration for the SONiC switch 25G,100G &amp; 400G ports<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-9 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.20.44.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1022\" height=\"732\" data-id=\"3442\" src=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.20.44.png\" alt=\"\" class=\"wp-image-3442\" srcset=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.20.44.png 1022w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.20.44-300x215.png 300w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.20.44-768x550.png 768w\" sizes=\"auto, (max-width: 1022px) 100vw, 1022px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-10 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.20.53.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1104\" height=\"402\" data-id=\"3443\" src=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.20.53.png\" alt=\"\" class=\"wp-image-3443\" srcset=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.20.53.png 1104w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.20.53-300x109.png 300w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.20.53-768x280.png 768w\" sizes=\"auto, (max-width: 1104px) 100vw, 1104px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-11 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.21.04.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1142\" height=\"590\" data-id=\"3444\" src=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.21.04.png\" alt=\"\" class=\"wp-image-3444\" srcset=\"https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.21.04.png 1142w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.21.04-300x155.png 300w, https:\/\/technobabble.us.to\/wp-content\/uploads\/2025\/02\/Screenshot-2025-02-13-at-15.21.04-768x397.png 768w\" sizes=\"auto, (max-width: 1142px) 100vw, 1142px\" \/><\/a><\/figure>\n<\/figure>\n","protected":false},"excerpt":{"rendered":"<p>When I was hired at eBay one of the first tasks I was given was to find an easy way to swap switches within a rack to help facilitate testing of various SONiC platforms. I knew this as ZTP from &hellip; <a href=\"https:\/\/technobabble.us.to\/?p=3415\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3415","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/technobabble.us.to\/index.php?rest_route=\/wp\/v2\/posts\/3415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/technobabble.us.to\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/technobabble.us.to\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/technobabble.us.to\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/technobabble.us.to\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3415"}],"version-history":[{"count":18,"href":"https:\/\/technobabble.us.to\/index.php?rest_route=\/wp\/v2\/posts\/3415\/revisions"}],"predecessor-version":[{"id":3454,"href":"https:\/\/technobabble.us.to\/index.php?rest_route=\/wp\/v2\/posts\/3415\/revisions\/3454"}],"wp:attachment":[{"href":"https:\/\/technobabble.us.to\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/technobabble.us.to\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/technobabble.us.to\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}