In this lesson, we will cover:

  • What is Nornir Scrapli?
  • What is Nornir?
  • How to install Nornir Scrapli.
  • Scrapli Nornir tasks.
  • Accessing the native Scrapli Response in Nornir.
  • The Nornir Scrapli print_structured_result function.

What is Nornir Scrapli?

Nornir Scrapli is the Scrapli plugin for Nornir. It provides support within Nornir for the majority of the Scrapli Core and Scrapli Netconf methods via Nornir tasks, along with providing an additional Nornir function. As Nornir does not currently support asyncio (it is based on multi-threaded synchronous execution), only the synchronous transports can be used.

What is Nornir?

For those of you new to Nornir:

Nornir is a pluggable multi-threaded framework, with inventory management that helps operate network devices.

Nornir is 100% Python. Whereas many automation frameworks (such as Ansible) use their own domain-specific language (DSL), Nornir lets you control everything from Python.

Nornir consists of the following core components:

  • Tasks – a task is a Python function that is run on a per-host basis.
  • Functions – functions run globally. For example, print_result is a function that prints the results of all of the executed tasks.
  • Inventory – defines the devices (and any related attributes) that our tasks will be performed against. The inventory structure consists of:
    • hosts.yaml – individual hosts and any related attributes.
    • groups.yaml – group definitions and any related attributes for the groups. Hosts are then added to these groups within hosts.yaml.
    • defaults.yaml – contains attributes that can be assigned to all hosts regardless of group assignment.

Installation

To install the Nornir Scrapli plugin, run the following:

$ pip3 install nornir-scrapli==2021.1.30

Note: This will also install Nornir, which will also be needed for getting hands-on in the upcoming sections.

Scrapli Nornir Tasks

A Nornir task is:

a reusable piece of code that implements some functionality for a single host.

Therefore, one of the main benefits of the Nornir Scrapli plugin is that it provides Nornir tasks for each of the different Scrapli methods (send_command, send_configs_from_file, etc). The full list of supported Scrapli Nornir tasks can be found below:

Available Tasks - Nornir Scrapli
Scrapli’s plugin for Nornir
Ready to Master Network Automation? Start Your Journey Today!
Our membership provides:
  • Full deep-dive course library (inc. Batfish, pyATS, Netmiko)
  • Code repositories inc. full course code, scripts and examples
  • 24x7 multi-vendor labs (Arista, Cisco, Juniper)
  • Private online community
  • Live monthly tech sessions
  • Access to tech session library

Join Now ➜
Close You've successfully subscribed to Packet Coders.
Close Success! Your account is fully activated, you now have access to all content.
Close Welcome back! You've successfully signed in.
Close Nearly there! To activate your account, please click the link in the email we just sent you.