Home Network automation Master the Nornir Python Automation Framework: Dive into Lesson 1 – Getting...

Master the Nornir Python Automation Framework: Dive into Lesson 1 – Getting Started with Nornir Training!


Welcome to the exciting world of network automation with Nornir, a powerful Python framework designed to simplify and streamline network management tasks. Embark on this journey with me as we delve into Lesson 1 – Getting Started with Nornir Training, laying the foundation for your network automation expertise.

Introduction to Nornir

Nornir emerged as a modern network automation framework, gaining popularity among network engineers and automation enthusiasts. Its core strength lies in its simplicity and flexibility, enabling users to easily automate complex network tasks using Python. Nornir’s modular design allows for seamless integration with other network automation tools,such as Ansible and Netmiko, providing a comprehensive toolkit for managing modern networks.

Prerequisites for Learning Nornir

Before embarking on your Nornir learning journey, ensure you have the following prerequisites:

  1. Basic Python Programming Knowledge: Familiarity with Python fundamentals, including data structures, control flow statements, and functions, is essential for understanding and utilizing Nornir effectively.

  2. Network Engineering Fundamentals: A grasp of networking concepts, such as IP addressing, routing, and switching, will provide a solid foundation for applying Nornir to real-world network automation scenarios.

  3. Virtual Environment Setup: Setting up a virtual environment using tools like virtualenv or pipenv is recommended to isolate your Nornir learning environment and avoid conflicts with other Python projects.

Installing Nornir

With the prerequisites in place, let’s begin by installing Nornir:

  1. Open your terminal: Launch a terminal or command prompt to execute commands.

  2. Install Nornir using pip: Execute the following command:

pip install nornir
  1. Verify Nornir installation: Once installed, verify the installation by running:
python -c "import nornir; print(nornir.__version__)"

This command should display the installed Nornir version, indicating successful installation.

Creating a Nornir Inventory

The Nornir inventory serves as the foundation for managing your network devices. It defines the groups and hosts you intend to automate. For instance, you can create groups like production, staging, and development, and assign hosts to each group based on their network topology.

Here’s an example of a simple Nornir inventory file named inventory.yaml:

        username: admin
        password: cisco123
        username: admin
        password: cisco123

In this example, the hosts section defines the inventory. The production group contains two subgroups, group1 and group2, each with a host defined by its hostname, username, and password.

Executing Nornir Tasks

Nornir tasks are Python functions that perform actions on your network devices. They are typically written using the @nornir.task decorator.

Here’s an example of a simple task named ping that checks the ping connectivity to the defined hosts:

from nornir import InitNornir
from nornir.core.task import Task

def ping(task):
    task.run(task='ping', hosts='all')

To execute this task, use:

python nornir.py --tasks ping

This command will execute the ping task on all hosts in the inventory.


Lesson 1 has provided you with a fundamental understanding of Nornir, covering installation, inventory creation, and task execution. As you progress through this learning journey, you’ll delve deeper into Nornir’s capabilities, mastering advanced concepts like task filters, jinja2 templating, and integration with other network automation tools. Embrace the power of Nornir and transform your network management experience with the efficiency and flexibility of Python automation.


Please enter your comment!
Please enter your name here