Nornir Training // Learn the Nornir Python Automation Framework // Lesson 1 - Getting Started

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome to this video in which I'm going to be going through Nornir which is the Python automation framework hello my name is Roger Perkin I am a network engineer I'm based in the UK and if you're watching this on YouTube and there's a link below the video which will point you to this blog post on my website which I'm referencing and if you're watching the video within that blog post then you're here already so let's get started so if you don't know what Nornir is it's a Python automation framework which has been written by David Barroso which was written to address some of the issues with the other automation tools that around at the moment mainly ansible which had of which whilst it's a great tool had a few flaws that needed to be addressed and that the main one was speed and flexibility so nor Nia has been built purely on a Python and it's written in Python and you write all your tasks in Python it runs very fast and if you can do something in Python then you can do it within nor Nia so it gives you a great deal of flexibility you do need to have some Python knowledge to run it so we'll be going through a bit of that now so before we go any further we need to install nor Nia so the first thing to do is literally to run this command which is pip3 install Nornir and I've got my Ubuntu machine here which I'm gonna run pip 3 install Nornir now this will go off and pull all the requirements down to get Norni while that's installing we'll go back to the post here and we should be installing at this time of recording which is March the 13th 2020 is 2.4.0 that's what we're hoping is going to come down and then once we've installed it we need to create a few files now these are YAML files it's the only YAML that you'll need to do just to get python here up and running and then once we've got it working everything else is written within Python itself so we will need a defaults file this defines any values that are relevant to your devices from a top level and there's a hierarchy to this then we get into groups where you can specify values that relate to groups of devices and then the hosts are the actual devices themselves and then the configure more file which we need to create just basically tells Nornir where all these other files are so we pop back into the installation so we we are there now so let's just see what we've got now for my environment I'm just installing this straight into my machine you could use a Python virtual environment to install it depending on your requirements but for now I'm just going to go through this tree you can see how it operates so there we've got Nornir 2.4.0 that's perfect and we need to start creating some files so within my machine I've got a Nornir directory which I've created and within that Nornir directory I'm gonna create an inventory folder where we go put all the inventory files so let's step back to the blog post see what I need to create first so we need to start with a config.yml or this file contains all the information about where the other three files are and we've got a file called config.yml and that goes in the root of the Nornir folder so let's just take all of that and in the Nornir root this is gonna be called config.yml or we're gonna pop in there now and go through what each line does so the number workers this tells Nornirhow many devices to go out and connect to at the same time so this is one of the big benefits of gnarnia in that it can go back to many many devices all at the same time run what it needs to impor the data back so we've got it set for a hundred at the moment which is more than adequate then we run this simple inventory plugin which is just part of the Nornir infrastructure and that allows us to then specify these device options here and this is literally telling nor Nia where we've got all the other bits so we've got the inventory /host camel groups.yml and the defaults.yml now the location of these files will be different to your environment but for me let's just see where I am I'm gonna be like this so I just need to take my file structure so this will be obviously different for you within your environment so this is where my files are so we've created now the config,yml and we now need to go and create these three files the house the groups and the defaults so in the order that I've got it specified here we're gonna create the host file yeah the host file looks like this so I'll copy that in and then we'll talk through what it's all about so within the inventory folder here I'm gonna do a host.yml so I've got actually in my environment five routers so I'm gonna copy these out a bit more so we can see them all we do is to find the name that you want the device to look like within nor near when you run the tasks and then the host name is the either the fully qualified domain name or the IP address now there are many many extra attributes that you can put into the host file which are detailed very well in the documentation and but the two that you absolutely have to have in place for this to work are the host name and the groups so for csr one the host name is well this is the IP that it's going to connect on and I've put it in the group csr reuters and then we've got csr two and i've also got three more this one's gonna be called csr three that one's too too too so yes our four and I've got these are csr routers which are running on eve ng on a ESXi host i've got swear so we'll connect to those shortly so this is now defined my hosts and that one is two to four so five routers they are all in the group CSR routers so let's go back to the post what is it saying now so the next file is that groups don't yeah more and that's one you can actually specify any data that is relevant to that group so we'll just copy that so within the inventory folder again we need another file which is groups yeah more so this one very simply I've just specified some data and I've put in one NTP server of 1.1.1.1 you can do anything you like in here whatever you like but I've just put this in for reference so we've got the file in place and then the the most important one is the defaults and this defines all the default values that apply to everything underneath it so normally runs on a very hierarchical structure so anything defined here will ripple down into every device but you can then override that structure further down the tree so the the last file was defaults we'll put that in yeah so I've just got three defaults you have to define the platform of the device and in this case we're running iOS and the username for these devices is Roger a password is Cisco so that's the three files defaults groups and hosts and then we've got our config file in place that's all looking good and then what I've got here then is five these five CSR Routers which I'll show you in a minute and the last thing is to actually write the Python scripts that we're going to run to connect to all the devices so this is the Python script here and I've called mine start be white so that's gonna be created in here so this one is called start.py and we'll pop that code in there so we we talk through this what we're gonna do is import from Nornir the init Nornir element this then specifies where the config file is which is this config file here and then from nor Nia we're going to import a couple of a bits which is the net Miko send command this is going to allow us to run the send command from within Miko and then we're going to import the print result which will allow us to print to the screen and then we're gonna run this command so this is net Miko send command and the string that we're going to run is shy P interface brief so what this script here will do is connect to every device my five Reuters I'll just bring them up here so I've got five CSR Reuters running on Eve ng and I'll just show you the IP of this one so this is 190 ones excite 1.2 20 and that one's 221 etc etc so it's going to connect to those five devices and run the command show IP interface brief so if everything's in place we should be able to now start python note we're not gonna do that I'm actually gonna run it straight from here Python three start py so this is gonna fail of course it is we've hit an error and the great thing about this is it tells you exactly where the problem is so it's telling me that I've got a problem on my house file in line 3 column 1 so this is a yeah more formatting error and I imagine when I did the copy paste that the formatting has not worked exactly and you can see this value here CSR 1 is out of line with this one here so if we just bring all of these in line so that's the problem with gamal is it it's very picky about the spacing now I will put all this code on my github so you can just pull it straight down without any of these problems so that should fix that so now this is gonna go off hit all 5 devices at once and run that command show IP interface brief bang there we go and print it to the screen so that's the information and you can see how quick it is it's once it's processed the commands it comes out and takes it so I hope this video has been informative for you and this is actually the the beginnings of a course I'm putting together on net miko so this is learning not no miko sorry of course I'm putting together on nor Nia which the details of that will be listed below the video and there's also a link on the website so I hope you've enjoyed this and please stay tuned for more videos and I hope that this is giving you an insight into how to start using noir Nia and how to install it and how to just get up and running and then we'll go into some more advanced videos at a later date so thank you and I'll see you in the next video
Info
Channel: Roger Perkin
Views: 5,448
Rating: undefined out of 5
Keywords: nornir python automation framework, nornir python, nornir python cisco, python nornir inventory, nornir python examples, nornir inventory, nornir examples, nornir python tutorial, network automation, nornir, nornir network automation, python, nornir tutorial, nornir training, nornir course, nornir automation course
Id: NnbtTZyQXkg
Channel Id: undefined
Length: 14min 25sec (865 seconds)
Published: Wed Mar 18 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.