From 828dd1a663ffae1ea074ea45f3e707f15385f235 Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal Date: Thu, 5 Jul 2018 10:58:54 +0530 Subject: [PATCH] To fix the NoneType error raised in ios_l2_interface when Access Mode VLAN is unassigned (#42312) * to fix the bug41657 * to fix review comment --- .../modules/network/ios/ios_l2_interface.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/network/ios/ios_l2_interface.py b/lib/ansible/modules/network/ios/ios_l2_interface.py index 361e5259c6a..ac48f576439 100644 --- a/lib/ansible/modules/network/ios/ios_l2_interface.py +++ b/lib/ansible/modules/network/ios/ios_l2_interface.py @@ -154,10 +154,18 @@ def interface_is_portchannel(name, module): def get_switchport(name, module): config = run_commands(module, ['show interface {0} switchport'.format(name)])[0] - mode = re.search(r'Administrative Mode: (?:.* )?(\w+)$', config, re.M).group(1) - access = re.search(r'Access Mode VLAN: (\d+)', config).group(1) - native = re.search(r'Trunking Native Mode VLAN: (\d+)', config).group(1) - trunk = re.search(r'Trunking VLANs Enabled: (.+)$', config, re.M).group(1) + mode = re.search(r'Administrative Mode: (?:.* )?(\w+)$', config, re.M) + access = re.search(r'Access Mode VLAN: (\d+)', config) + native = re.search(r'Trunking Native Mode VLAN: (\d+)', config) + trunk = re.search(r'Trunking VLANs Enabled: (.+)$', config, re.M) + if mode: + mode = mode.group(1) + if access: + access = access.group(1) + if native: + native = native.group(1) + if trunk: + trunk = trunk.group(1) if trunk == 'ALL': trunk = '1-4094'