Replies: 4 comments 5 replies
-
Probably need to include your code. |
Beta Was this translation helpful? Give feedback.
-
Hello sir,, This is my script I was trying with the nr.filter. or nr.inventory.hosts but not sure. Thanks for your help. from nornir import InitNornir
from nornir_scrapli.tasks import send_command
from nornir_utils.plugins.functions import print_result
from nornir.core.filter import F # Added(2)
import os
import json
from colorama import Fore, init
nr = InitNornir(config_file="config.yaml")
#PRINT HOST INVENTORY
print("=" * 50)
print("HOSTS IN INVENTORY")
for host in nr.inventory.hosts.keys():
print(f"Host: {Fore.CYAN}{host}")
print(f"There are {len(nr.inventory.hosts.keys())} hosts in this inventory.")
print("=" * 50)
'''
CLEAR OS SCREEN
'''
CLEAR = "clear"
os.system(CLEAR)
'''
CHOOSE HOSTs
'''
target = input("Choose hosts: ")
commands = txt.split(",")
'''
CHOOSE COMMANDs
'''
ctarget = input("Insert Commands: ")
ccommands = txt.split(",")
#SEND COMMANDs
def show_commands(task):
task.run(task=send_commands, commands=ccommands) |
Beta Was this translation helpful? Give feedback.
-
Try using nornir-salt FFun function, it simplifies filtering. Install it first - This is sample code:
Should print results to screen in a dictionary format keyed by show command string. Reference and details: |
Beta Was this translation helpful? Give feedback.
-
Hi Team, this is just a working sample of the code: the total 2 boxes in the lab, and we filtered one by name:
|
Beta Was this translation helpful? Give feedback.
-
Hello,
I have a simple script send commands, Im changing it so I choose over what devices I want to execute the script, but I can make it work with either nr.filter or nr.inventory.
Any help is more then welcome
thanks.
Beta Was this translation helpful? Give feedback.
All reactions