Nornir Runner Module
Nornir Runner module reference.
Note
Runner module functions executed on same machine where salt-master process runs.
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 Falsejob_retry – how many times to retry command if no return from minions, default 0
job_timeout – seconds to wait for return from minions, overrides
--timeout
option, default 30stable – (str, dict or bool) supplied to TabulateFormatter under
table
keyword to control output table formattingheaders – (list) headers list, default
["minion", "host", "ip", "platform", "groups"]
reverse – (bool) reverse table order if True, default is False
sortby – (str) header to sort table by, default is
host
Sample Usage:
salt-run nr.inventory host_name_id salt-run nr.inventory FB="host_name_id" FP="10.1.2.0/24"
If it takes too long to get output because of non-responding/unreachable minions, specify
--timeout
orjob_timeout
option to shorten waiting time,job_timeout
overrides--timeout
. Alternatively, instead of targeting all nornir based proxy minions,tgt
andtgt_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 | host | ip | platform | groups | +---+--------+----------+----------------+----------+--------+ | 0 | nrp1 | IOL1 | 192.168.217.10 | ios | lab | +---+--------+----------+----------------+----------+--------+
- salt_nornir.runners.nornir_proxy_runner_module.call(*args, **kwargs)
Method to call any Nornir Proxy Minion Execution Module function against minions. By default this function targets all Nornir Proxy Minions, allowing to simplify targeting hosts managed by them.
- Parameters
fun – (str) Nornir Proxy Minion Execution Module function name e.g.
cli, cfg, nc, gnmi
etc.tgt – (str) SaltStack Nornir Proxy Minions to target, targets all of them by default -
proxy:proxytype:nornir
tgt_type – (str) SaltStack targeting type to use, default is
pillar
job_retry – (int) how many times to retry if no results returned from all minions, default 0
timeout – (int) seconds to wait for results from minions before retry, default 300s
progress – progress display type to use - bars, raw, log, if False, no progress displayed
ret_struct – results return structure, default is
dictionary
, also can belist
args – (list) any other arguments to use with call function
kwargs – (dict) any other keyword arguments to use with call function
Sample Usage:
salt-run nr.call fun="cfg" "logging host 1.2.3.4" FC="CORE" salt-run nr.call cli "show clock" FB="*" tgt="nr-minion-id*" tgt_type="glob"
- salt_nornir.runners.nornir_proxy_runner_module.event(jid='all', tag=None, progress='log', stop_signal=None)
Function to listen to events emitted by Nornir Proxy Minions. Matched event printed to terminal.
- Parameters
tag – (str) tag regex string, default is
nornir\-proxy/.*
jid – (int, str) Job ID to listen events for, default is
all
progress – (str) progress display mode -
log
,raw
,bars
,tree
stop_signal –
(obj) thread Event object, stops listening to events if
stop_signal.is_set()
, ifstop_signal is None
, listens and print events until keyboard interrupt hit -ctrl+c
bars
andtree
progress display modes use Rich library, to properly display various symbols and characters need to make sure to use utf-8 encoding for your environment, to ensure that issue these commands in your terminal:[root@salt-master ~]# PYTHONIOENCODING=utf-8 [root@salt-master ~]# export PYTHONIOENCODING