NORNIR TUTORIAL!! Everything you need to know about the Nornir Automation Framework

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right welcome back to ultra config tutorials in today's video we're going to be talking about the nor near automation framework so when designing a network automation solution it is critical to keep scalability as a key priority how can jobs be executed on a large number of devices in parallel what about inventory management one solution is nor near an automation framework native to the Python programming language today let's do a deep dive tutorial we'll start with the basics and then manager Cisco and juniper router to show off the power of gnarnia alright let's get to it if you love Python you will love nor Nia nor Nia's full integration with Python is one of its greatest highlights users will only ever need to write Python code when using the nor near framework this isn't the case for most frameworks take ansible for example play books are written with a custom DSL that's a domain-specific language so is the lack of the DSL a good thing there's going to be pros and cons to every design decision while a DSL can simplify readability among other benefits there are advantages to scrapping a DSL for a generalized programming language here's a few a smaller learning curve users will not have to learn any new syntax as long as they know the programming language they will rapidly pick up on the development pattern for the DSL less framework it also offers a seamless user experience users can seamlessly leverage libraries and features of the programming language directly into their code with a DSL this is not the case and finally easy debugging users can easily debug their code using tools built for the programming language a framework with a DSL would require its own solution for debugging ok so what are some of the other highlights of gnarnia nor Nia offers parallel job execution that is it can execute jobs against devices in parallel for small networks with few devices there usually isn't much of a need for parallel job execution but as networks grow larger this is bound to change take an example imagine network with 1000 devices and a backup task that takes 10 seconds to execute against a single device simple math tells us that these jobs will take almost three hours to complete if executed sequentially with 100 parallel workers however these jobs could all be executed in less than two minutes moving on inventory management is another great highlight of gnarnia in a large network how can a user run a task against all Cisco devices but not Juniper devices how could a user run a task against all routers but not switches the one year's inventory solution allows users to map devices into groups users can then easily execute jobs against subsets of their network all right let's get into some practical examples of how all this works first off we'll open up a terminal and install nor new using pip the Python package manager with that done let's discuss inventory management after Nora is initialized inventory is managed inside a Python object during the initialization however we have several options for passing in our inventory data for a large production network our recommendation is to manage inventory inside a database for today though we'll keep things basic by utilizing the simple inventory plug-in this plug-in allows us to pass in our inventory data from Gemmell files to get started let's create an inventory folder at the root of our project well then add three files inside this folder the host dot Yama file is where we specify metadata about our devices such as IP addresses fqdn x' credentials etc we can also specify a list of groups that each device belongs to in our virtual lab we have one Cisco router at one juniper router will add our host data in now most of the data here is self-explanatory except for the connection options object this object is necessary on the Cisco device to specify a secret this is the password that napalm will use to enter enable mode on the router next we'll create our group CML file these groups correspond to those referenced in our hosts AML file finally we'll create our default CML file this is where default values are specified nor nia will use these values unless they are overridden within the hosts or groups file without inventory out of the way let's now create a new file at the root of our project entitled config yeah Mel earlier we discussed parallel job execution the num workers object allows us to set an upper bound on the maximum number of concurrent jobs this is useful for granular control over the hardware resources consumed by nor Nia the remainder of our config file specifies our inventory metadata will now create a new file for our Python program entitled nor Nia tutorial py at the head of the file we'll import our dependencies let's now define a method for prettyprint in Python dictionaries that will come in handy for printing out nor Nia objects will now add the code to initialize nor Nia this will read our config file and load our inventory we can now print our inventory to the screen to ensure it loaded correctly executing our program will now display our inventory as a JSON object you will notice some null values within o inventory that's not a problem nor Nia will inherit these values from higher levels in the inventory hierarchy moving on let's demonstrate how we can execute a job against our inventory will use the Napalm driver to interact with our devices let's retrieve the IP interface configuration for now routers executing a Python program now yields the nor Nia job blogs these logs are readable for humans but how can we access our results as Python dictionaries users need to know this if they wish to pass a response without using complex regular expressions so how can we do it it's actually very easy just grab the result key inside the returned objects for a host check it out we'll grab the result from the cisco router and print it to the screen running our program should now yield a nicely formatted JSON response there we go all looks well so earlier we mentioned that more Nia allows us to control which devices we would like to execute our tasks against we can achieve this using filters let's create a filter that will only run our job against Cisco devices we're able to do this by filtering our inventory with the condition that the platform must equal iOS our nor near job blog will now reveal that the task was only run against our Cisco device and there we go the filter worked as expected so that's everything essential we need to know to get started with gnarnia before i end today's video i'll also shout out ultra config noor Nia is great at managing task execution and network inventory but how do you automate the generation of Network config ultra convict is a powerful piece of software for automating the generation of Network config if you work in the network engineering industry I highly recommend you to check it out the software includes an API to fully enable into n network automation and the best part about it the software is free to use with our free forever plan a link to the software will be in the description we'll also put a link in the description to a written form of today's tutorial for you to try it yourself that'll be it for today thanks for watching and I'll see you all in the next video
Info
Channel: Ultra Config
Views: 1,948
Rating: undefined out of 5
Keywords: nornir, nornir tutorial, napalm, network automation, learn nornir, cisco automation, juniper automation
Id: NRnYlPC7nH0
Channel Id: undefined
Length: 8min 49sec (529 seconds)
Published: Sat May 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.