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.
Here are some YouTube videos for Nornir Python Automation Framework:
- Nornir Training // Learn the Nornir Python Automation Framework // Lesson 1 – Getting Started by Roger Perkin
- Automate your network with Nornir – Python automation framework by Cisco DevNet
- Nornir Network Automation Python Framework Tutorial: Create Device Inventory &run tasks concurrently by NetworkEvolution
- Python: Nornir Automation framework Intro :How to use Nornir library with Cisco Arista Devices
Prerequisites for Learning Nornir
Before embarking on your Nornir learning journey, ensure you have the following prerequisites:
Basic Python Programming Knowledge: Familiarity with Python fundamentals, including data structures, control flow statements, and functions, is essential for understanding and utilizing Nornir effectively.
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.
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.
With the prerequisites in place, let’s begin by installing Nornir:
Open your terminal: Launch a terminal or command prompt to execute commands.
Install Nornir using pip: Execute the following command:
pip install nornir
- 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
development, and assign hosts to each group based on their network topology.
Here’s an example of a simple Nornir inventory file named
In this example, the
hosts section defines the inventory. The
production group contains two subgroups,
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
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
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.