-
Notifications
You must be signed in to change notification settings - Fork 1
/
nornir-sendconfigfile.py
22 lines (20 loc) · 1023 Bytes
/
nornir-sendconfigfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#python script using netmiko plugin send_config to send configuration
#from a text file "randomconfig.txt"
import getpass
from nornir import InitNornir
from nornir_netmiko.tasks import netmiko_send_config
from nornir_utils.plugins.functions import print_result
#importing netmiko send_config library
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 send_config_test(task):
task.run(task=netmiko_send_config, config_file="netmiko-randomconfig.txt")
#function is sending the configuration commands in the file to the hosts
results = nr.run(task=send_config_test)
print_result(results)
#setting the object results to output of the send_config_test function