Nornir Runner Module

Nornir Runner module reference.

Note

Keep in mind that runner module functions executed on same machine where salt-master process runs.

Dependencies

  • Tabulate required by nr.inventory to return table results

Introduction

Nornir-runner module runs on SALT Master and allows to interact with devices behind Nornir proxy minions.

Nornir Runner module functions

salt_nornir.runners.nornir_proxy_runner_module.inventory(*args, **kwargs)

Function to return brief inventory data for certain hosts in a table format.

Parameters
  • FB – glob pattern matching hostnames of devices behind Nornir

  • Fx – additional filters to filter hosts, e.g. FG, FP, FL etc.

  • tgt – nornir proxy minion target, by default targets all - “proxy:proxytype:nornir”

  • tgt_type – SALT targeting type to use, by default “pillar”

  • verbose – boolean, returns nr.cli output as is if True, flattens to dictionary keyed by devices hostnames if False, default False

  • retry – how many times to retry command if no return from minions, default 3

  • job_timeout – seconds to wait for return from minions, overrides --timeout option, default 30s

  • tk – dictionary, **kwargs to use with tabulate.tabulate method, reference tabulate documentation

Sample Usage:

salt-run nr.inventory host_name_id
salt-run nr.inventory FB="host_name_id" FP="10.1.2.0/24"
salt-run nr.inventory FB="host_name_id" FP="10.1.2.0/24" tk='{"tablefmt": "jira"}'

If it takes too long to get output because of non-responding/unreachable minions, specify --timeout or job_timeout option to shorten waiting time, job_timeout overrides --timeout. Alternatively, instead of targeting all nornir based proxy minions, tgt and tgt_type can be used to target a subset of them:

salt-run nr.inventory host_name_id --timeout=10
salt-run nr.inventory host_name_id job_timeout=10 tgt="nornir-proxy-id" tgt_type="glob"

Sample output:

[root@localhost /]# salt-run nr.inventory IOL1
+---+--------+----------+----------------+----------+--------+
|   | minion | hostname |       ip       | platform | groups |
+---+--------+----------+----------------+----------+--------+
| 0 |  nrp1  |   IOL1   | 192.168.217.10 |   ios    |  lab   |
+---+--------+----------+----------------+----------+--------+
salt_nornir.runners.nornir_proxy_runner_module.cli(*args, **kwargs)

Method to retrieve commands output from devices behind Nornir Proxies using nr.cli execution module function.

Parameters
  • FB – glob pattern matching hostnames of devices behind Nornir

  • Fx – additional filters to filter hosts, e.g. FG, FP, FL etc.

  • tgt – nornir proxy minion target, by default targets all - “proxy:proxytype:nornir”

  • tgt_type – SALT targeting type to use, by default “pillar”

  • verbose – boolean, returns nr.cli output as is if True, flattens to dictionary keyed by devices hostnames if False, default False

  • retry – how many times to retry command if no return from minions, default 3

  • job_timeout – seconds to wait for return from minions, overrides --timeout option, default 30s

All the parameters supported by nr.cli execution module function supported by this function as well.

Parameters
  • commands – list of commands

  • netmiko_kwargs – kwargs to pass on to netmiko send_command methods

  • add_details – boolean, to include details in result or not

  • add_cpid_to_task_name – boolean, include Child Process ID (cpid) for debugging

  • plugin – name of send command task plugin to use - netmiko (default) or scrapli

  • match – regular expression pattern to search for in results, similar to Cisco include or Juniper match pipe commands

  • before – used with match, number of lines before match to include in results, default is 0

Sample Usage:

salt-run nr.cli hostname-id "show clock" "show run" FB="IOL[12]" netmiko_kwargs='{"use_timing": True, "delay_factor": 4}'
salt-run nr.cli hostname-id commands='["show clock", "show run"]' FB="IOL[12]" netmiko_kwargs='{"strip_prompt": False}'

If it takes too long to get output because of non-responding/unreachable minions, specify --timeout or job_timeout option to shorten waiting time, job_timeout overrides --timeout. Alternatively, instead of targeting all nornir based proxy minions, tgt and tgt_type can be used to target a subset of them:

salt-run nr.inventory host_name_id --timeout=10
salt-run nr.inventory host_name_id job_timeout=10 tgt="nornir-proxy-id" tgt_type="glob"