Conditionally reading in secret for Connect_Handler #3184
Replies: 1 comment
-
This seemed to work: when I passed in a file like this: and now it overrides the enable with try except clauses, and parses the commands it is able to parse, or skips them. This is good for an passing variables around to different drivers when need to use another connection driver (i.e NAPALM)... |
Beta Was this translation helpful? Give feedback.
-
I'm trying to conditionally read in secret, depending on an input file, whether secret is tied to the device or not.
for example here's one line:
{"ip":"10.0.1.130", "username":"cisco", "password":"cisco123", "secret":"python", "device_type": "cisco_ios", "header":"Netmiko"}
however some lines may not include secret:
{"ip":"10.0.5.1", "username":"juniper", "password":"cisco123", "device_type": "juniper", "header":"Netmiko"}
so I tried this:
ConnectHandler = netmiko.ConnectHandler(
device_type=device_type,
host=ip,
username=username,
password=password,
port=22,
secret=data["secret"] if data["secret"] else "",
)
It's still parsing secret as empty/ ""
and so is there a way for me to skip over secret in the ConnectHandler if it's not listed for one of the device in my input list?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions