I have a usage question in a fairly complex setup, but I’ve tried to boil down the actual question to something simple and generic.
Let’s say I have a task that uses netmiko to execute ‘show clock’ on hosts.
from nornir.core.task import Task, Result
from netmiko import ConnectHandler
def show_clock(task: Task) -> Result:
cmd = 'show clock'
host = host_data
connection = {'device_type': host.platform,
'host': host.name,
'username': host.username,
'password': host.password}
net_connect = ConnectHandler(**connection)
result = net_connect.send_command(cmd)
return Result(
host=task.host,
result=result)
And when I execute it, it correctly connects and grabs the output for n hosts.
result = nr.run(task=show_clock)
>>> result['host_n'][0].result
'21:44:03.088 gmt Fri Oct 23 2020'
Lets also say I have another task, that will accept a formatted datestamp similar to our previous results, and return the difference between that stamp, and a new execution of show clock
.
def show_clock_compare(task: Task, old_stamp: str = None) -> Result:
...
Assuming I have n > 1
hosts, how can I feed the current result data back into show_clock_compare
dynamically for each host.
To put it another way, how can I have result['host_n'][0].result
passed into show_clock_compare
as if it were executed like:
nr.run(task=show_clock_compare, old_stamp=result['host_n'][0].result)
I’ve thought about parsing the result data back into each host, so it’s passed into tasks as part of task.host
making it accessible, but this feels like a clunky unnecessary step, and I’m hoping something more elegant has to exist.
TIA for the help!