-
Notifications
You must be signed in to change notification settings - Fork 1
/
banner_filter4.py
28 lines (26 loc) · 1.19 KB
/
banner_filter4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
INSTALL THE FOLLOWING:
pip3 install nornir
pip3 install nornir-scrapli
pip3 install nornir_utils
"""
import getpass
from nornir import InitNornir
from nornir_scrapli.tasks import send_configs_from_file
from nornir_utils.plugins.functions import print_result
from nornir.core.filter import F
# Python script using F filter to filter out specific hosts using data in the host profile
nr = InitNornir(config_file="config.yaml")
#The above line is telling nornir where the config file is located
user = input("Enter your username: ")
password = getpass.getpass(prompt="Enter your password: ")
nr.inventory.defaults.username = user
nr.inventory.defaults.password = password
#The above lines will prompt the user to enter their username and password and use that input to connect to the devices
def banner_push(task):
task.run(task=send_configs_from_file, name="Configuring Banner", file="not_tennis_banner.txt")
# creating the function to use send_configs_from_file to send the txt from the not_tennis_banner.txt file
not_tennis = nr.filter(~F(location="court"))
# using F filter this time to filter out any host who has court in their data profile
results = not_tennis.run(task=banner_push)
print_result(results)