I'm trying to get the AAA configuration in my switch to compare the exact configuration, but when i try to gather with the exact same config it doesn't show that as a correct configuration.
Here's the example :
def check_config(config):
parse = CiscoConfParse('test_config.txt', syntax='ios')
tcs_obj = parse.find_lines(config)
if parse.find_objects(config):
print(parse.find_objects(config))
else:
print(f'Config {config} not found!!!')
check_config('aaa authentication login default group tacacs+ local')
The result:
Config aaa authentication login default group tacacs+ local not found!!!
But when i tried to remove the 'local', it showed the line.
check_config('aaa authentication login default group tacacs+')
[<IOSCfgLine # 34 'aaa authentication login default group tacacs+ local'>]
The reason is because CiscoConfParse objects use regex for their input. So, when you pass
aaa authentication login default group tacacs+ local, the+acts as a regex operator.So, the solution here is to pass a regex string to the function and use the escape character
\on the regex operator+.Below config works:
All that was updated was the string passed to the function
check_config. Put anrbefore the quotes and put an escape\before the+operator.