Nornir The Python Automation Framework
Nornir The Python Automation Framework
Framework
You are here: Home / Network Automation Blog / Network Automation with Python / Nornir Training – Learn the Python Automation Framework
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Get my Free guide on
getting started with
Network Automation
Powered By ConvertKit
What is Nornir?
The Nornir Python automation framework is written in Python and designed to be used for network
automation tasks. It is much faster and gives you more exibility than it’s friend Ansible.
Ansible, which is also written in Python is currently the most popular network automation tool in use today
but it does have some limitations which Nornir has been written to address.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
and Ansible, in this video I try to answer the very
common question of Get my Free guide on
“Nornir vs Ansible“ Whichgetting
is best?started with
Network Automation
Written by David Barroso with some help from Kirk Byers, Nornir allows you to use any feature available to
you within Python to perform your network automation.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Nornir Training Video Get my Free guide on
getting started with
If you want to learn NornirNetwork Automation
by watching videos, the
entire contents of this blog post are covered in this
video. Your rst name
In this Nornir demo I will take you from the very beginning. We will install Nornir, con gure all
the dependencies and run your rst task.
If you are looking for a Nornir training course check the link below.
Nornir Course
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Get my Free guide on
getting started with
Network Automation
Nornir needs to be installed on Linux and for this tutorial I am using an Ubuntu 18.04 desktop
We respect image.Unsubscribe
your privacy.
at anytime.
You simply run the command pip3 install nornir Powered By ConvertKit
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Get my Free guide on
getting started with
Network Automation
Once it’s installed you can verify it’s there with the command pip3 freeze which will list all yourByinstalled
Powered ConvertKit
libraries.
Now we have Nornir installed we need to setup a few things. We need to create four les.
defaults.yml
groups.yml
hosts.yml
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
con g.yml
Get my Free guide on
getting started with
You can download the les here from my Github Network Automation
For this tutorial I have created a folder called Nornir on my machine and we will create the con g.yml in the
root of that folder. Send me the guide
num_workers: 100
inventory:
plugin: "nornir.plugins.inventory.simple.SimpleInventory"
options:
host_file: "/inventory/hosts.yml"
group_file: "/inventory/groups.yml"
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
defaults_file: "/inventory/defaults.yml"
Get my Free guide on
getting started with
You will need to change the le path if you have your les elsewhere. Network Automation
Within this le the num_workers speci es how many devices you want Nornir to connect to at once.
Your rst name
Then the inventory plugin is de ned and under the options you specify where the Your
other three les are.
email address
Then I have created a folder called inventory where I have the other three les.
One of the most important les within Nornir is the inventory or hosts le, this lists all thePowered
devices that you
By ConvertKit
want to connect to and is written in YAML. Inventory management is a big feature of Nornir!
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
hostname: 192.168.1.220
CSR2:
Your rst name
hostname: 192.168.1.221
Your email address
groups:
- CSR_Routers
Send me the guide
Nornir groups.yaml
The next le is groups.yml in this le you can specify data that is relevant to that group. Nornir operates a
very hierarchical structure so values are inherited down so anything in defaults affects all devices, and then
anything in groups affects devices in that group only.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
## Nornir Groups File
---
Get my Free guide on
CSR_Routers:
getting started with
Network Automation
data:
servers:
Your email address
- 1.1.1.1
This le contains all the information that is relevant to all devices. Any value in here can be overridden by
specifying it lower down the tree i.e in the groups le or even down to a host le level.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
platform: ios
Get my Free guide on
username: roger getting started with
Network Automation
password: cisco
Powered By ConvertKit
Nornir Example
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Now whilst you could do all of this with pure Python and use the libraries Netmiko and Napalm yourself.
Nornir takes all the hard work out of that and lets you use Python but within a framework
Get my so youguide
Free can on
bene t from the inventory and the native use of Netmiko behind the scenes. getting started with
Network Automation
This gives you the bene t of using Python for Network Automation within theYour
Nornir Framework
rst name
which gives you the bene ts of inventory and connection handling.
Your email address
So now we have all the pieces in place we need one more le and that is the Python script we are going to
run. Send me the guide
This le will reference the con g.yml le we created earlier, import a few libraries and then runBythe
Powered ConvertKit
nr = InitNornir("config.yml")
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
print_result(result)
Get my Free guide on
getting started with
This le imports the relevant libraries from Nornir and then speci es the commands we are going to send
Network Automation
to our routers. In this case sh ip int brief
Your rst name
So running this Python script will do a sh ip int brief on each router and then print the results to the screen.
Your email address
Let’s drop into our command line and run the Python script!
Just type python3 start.py and you should see this Send me the guide
Powered By ConvertKit
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Get my Free guide on
getting started with
Network Automation
What is Nornir?
at anytime.
Powered By ConvertKit
Nornir is a Python Automation Framework, it utilises already established Python libraries like Netmiko and
Napalm to perform network automation tasks. Allowing you to focus on writing Python scripts for your
tasks, whilst letting Nornir take care of the inventory and connectivity for devices.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
What does a network automation engineer
Get do?
my Free guide on
getting started with
Network engineers of the future are going to have to become pro cient in using Python,
NetworkGit,Automation
Nornir Ansible
and to learn coding to be able to do their jobs. A network automation engineer is someone who has
embraced these skills and is using them in their daily job to improve ef ciency andYour
productivity
rst name when
So hopefully at this point you should have been able to connect to a few devices and run a your
We respect simple
privacy. Unsubscribe
Powered By ConvertKit
Share Tweet S 0
Powered By ConvertKit
Sign up to my FREE
Your rst name
7 Day Network Automation
Course
Your email address
You will receive one short lesson each
day to get you started on the road to
network automation Subscribe
Powered By ConvertKit
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Get my Free guide on
getting started with
Network Automation
Comments
We respect your privacy. Unsubscribe
at anytime.
Powered By ConvertKit
This provided information is really so nice, thanks for giving this post and the more skills to develop
Reply
Mithun says
September 10, 2020 at 12:44 am
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
do you have the full course for nornir
Get my Free guide on
Reply getting started with
Network Automation
Reply
Send me the guide
Powered By ConvertKit
Leave a Reply
Your email address will not be published. Required elds are marked *
Comment
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Get my Free guide on
getting started with
Network Automation
Name *
Your rst name
Email *
Powered By ConvertKit
Post Comment
Hi I'm Roger.
CCIE #50038
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Currently based in the UK working for a Cisco Gold Partner as a Senior Network & Security Consultant.
About Roger | Twitter | Linkedin
Get my Free guide on
getting started with
Network Automation
Powered By ConvertKit
Get my tips on how to survive studying for the CCIE Lab Exam
This is not a technical guide. These tips are from my journey to become a CCIE. Learn from my mistakes on how to survive studying and
preparing for the Lab Exam.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Get my Free guide on
Recent Posts getting started with
Network Automation
Should Network Engineers Learn Python?
pyATS Genie Tutorial Your rst name
Powered By ConvertKit
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Get my Free guide on
getting started with
Network Automation
Powered By ConvertKit
Ansible vs Nornir
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Get my Free guide on
getting started with
Network Automation
Powered By ConvertKit
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Get my Free guide on
getting started with
Network Automation
About Roger CCIE Blog
I'm Roger, a UK based network consultant My CCIE Journey Your rst name
currently working for a Cisco Gold Partner. My CCIE Study Plan
I am CCIE #50038 and am a Network Cisco Continuing
Your email address
Automation envalgelist. Education Program
ROUTING
PROTOCOLS Send me the guide
Powered By ConvertKit
Network Tools
Airconsole Bluetooth
Console Cable
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD