06-25-2023 10:26 PM
Hi guys,
Does anyone know of a script to use or can help out with a link that simply shows how to loop through multiple devices to program them using ncclient?
Regards
Champ
Solved! Go to Solution.
06-25-2023 11:08 PM
Hi
As a basic example you can simply loop over a list of devices:
from ncclient import manager
devices = [
"1.1.1.1",
"1.1.1.2",
"hostname.xyz",
"1.1.1.3"
]
username = "admin"
password = "secret"
cfg = """
<config>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<banner>
<motd>
<banner>Welcome to this device. Have a nice day!</banner>
</motd>
</banner>
</native>
</config>
"""
for dev in devices:
with manager.connect(
host=dev,
port=830,
username=username,
password=password,
hostkey_verify=False,
) as m:
res = m.edit_config(target="running", config=cfg)
if res.ok:
print(f"successfully configured {dev}")
HTH
Marcel
06-25-2023 11:08 PM
Hi
As a basic example you can simply loop over a list of devices:
from ncclient import manager
devices = [
"1.1.1.1",
"1.1.1.2",
"hostname.xyz",
"1.1.1.3"
]
username = "admin"
password = "secret"
cfg = """
<config>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<banner>
<motd>
<banner>Welcome to this device. Have a nice day!</banner>
</motd>
</banner>
</native>
</config>
"""
for dev in devices:
with manager.connect(
host=dev,
port=830,
username=username,
password=password,
hostkey_verify=False,
) as m:
res = m.edit_config(target="running", config=cfg)
if res.ok:
print(f"successfully configured {dev}")
HTH
Marcel
06-26-2023 01:04 AM
Thanks Marcel,
That worked.
I might use functions to group routers for similar config and see how far I go.
Thanks
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide