Skip to content

Nornir: Introduction & Getting Started

Nornir is a pure Python automation framework for network engineers. It provides inventory management, task execution, and plugin support for network automation workflows.

Why Use Nornir?

  • Automate network device configuration and validation
  • Use Python for full programmability
  • Integrate with other Python libraries and tools

How Nornir Works

  • Inventory is defined in YAML or Python
  • Tasks are Python functions (or plugins)
  • Results are returned as Python objects for further processing

Quick Start Example

  1. Install Nornir:
    pip install nornir
    
  2. Create a simple inventory (inventory/hosts.yaml):
    r1:
      hostname: 192.0.2.1
      username: admin
      password: admin
    
  3. Write a basic script (main.py):
    from nornir import InitNornir
    from nornir.core.task import Task, Result
    
    def hello_world(task: Task) -> Result:
        return Result(host=task.host, result=f"Hello from {task.host.name}")
    
    nr = InitNornir()
    result = nr.run(task=hello_world)
    print(result)
    
  4. Run the script:
    python main.py
    

Learn More