cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
442
Views
2
Helpful
2
Replies

Using Netconf NCCLIENT to automate multiple devices at once

nwekechampion
Level 3
Level 3

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

1 Accepted Solution

Accepted Solutions

Marcel Zehnder
Spotlight
Spotlight

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

View solution in original post

2 Replies 2

Marcel Zehnder
Spotlight
Spotlight

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

Thanks Marcel,

That worked.

I might use functions to group routers for similar config and see how far I go.

Thanks