Wednesday, December 16, 2020

ciscoconfparse 802.1x automation

I am working on automating 802.1x configurations for cisco switches. I have been toying with this python script. What I would like to do though is us the vlan_id in "switchport access vlan 10" as a variable to add to the command " authentication event server dead action authorize vlan 10 " I don't want to have to worry about what access vlan is assigned to a port.

from ciscoconfparse import CiscoConfParse
parse = CiscoConfParse('h:/Scripts/Cisco_Python/10.220.151.1')
for intf in parse.find_objects(r'^interface.+?thernet'):
    is_switchport_access = intf.has_child_with(r'switchport access vlan 10')
    has_dot1x_pae_authenticator = intf.has_child_with(r'dot1x pae authenticator')
if is_switchport_access and (not has_dot1x_pae_authenticator):
         intf.append_to_family(' device-tracking attach-policy ISE-DEVICE-TRACK-POL')
         intf.append_to_family(' authentication event server dead action authorize vlan 10')
         intf.append_to_family(' authentication event server dead action authorize voice')
         intf.append_to_family(' authentication host-mode multi-auth')
         intf.append_to_family(' authentication open')
         intf.append_to_family(' authentication order dot1x mab')
         intf.append_to_family(' authentication priority dot1x mab')
         intf.append_to_family(' authentication port-control auto')
         intf.append_to_family(' authentication periodic')
         intf.append_to_family(' authentication timer reauthenticate server')
         intf.append_to_family(' mab')
         intf.append_to_family(' dot1x pae authenticator')
         intf.append_to_family(' dot1x timeout tx-period 3')
## Write the new configuration
parse.save_as('h:/Scripts/Cisco_Python/10.220.151.1new')



No comments:

Post a Comment