Replies: 1 comment 2 replies
-
Hi fdervisi, first of all, try to separate the task execution and the evaluation of the task's result. It helps with separation of concerns (i.e. don't do too many different things in one function) and maintaining code. In your case, I'd return just the result and then do whatever it must be done with However, I've run into similar problems you had, and solved it by wrapping per-host-results into another Result, basically executing per-host-pings as subtasks. Maybe try this: def ping_verification(task, linux):
for host in linux.inventory.hosts:
linux_ip = linux.inventory.hosts[host]['ip']
result = task.run(
task=netmiko_send_command, command_string=f"ping {linux_ip} -c1"
)
return Result(host=task.host, result="All pings executed") I find the evaluation of nornir results always a little bit bewildering (What's the structure of the result's data? It always seems to differ!), so I usually set a breakpoint at Just two side notes:
Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Dear Experts,
How can I access a returned value, from a Nornir task? Here is an example:
def start_ping_verification() will issue an other task which should do a full mesh ping. In def ping_verification(task,linux) I want to return, all the devices, which failed as a dictionary, but I don't know how I can access ist, because of the MultiResult object!?
Can somebody please help me?
Beta Was this translation helpful? Give feedback.
All reactions