From 7b19c2843810e55156a52435dcee5c0fc4aec8af Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Mon, 27 Nov 2017 22:56:39 +0530 Subject: [PATCH] nxos_vrf_interface fix (#33249) Signed-off-by: Trishna Guha --- .../modules/network/nxos/nxos_vrf_interface.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py index ac61b71997f..74b9b207e66 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py @@ -121,10 +121,18 @@ def get_interface_mode(interface, intf_type, module): if intf_type in ['ethernet', 'portchannel']: body = execute_show_command(command, module) - interface_table = body['TABLE_interface']['ROW_interface'] - mode = str(interface_table.get('eth_mode', 'layer3')) - if mode == 'access' or mode == 'trunk': - mode = 'layer2' + try: + interface_table = body['TABLE_interface']['ROW_interface'] + except KeyError: + return mode + + if interface_table and isinstance(interface_table, dict): + mode = str(interface_table.get('eth_mode', 'layer3')) + if mode == 'access' or mode == 'trunk': + mode = 'layer2' + else: + return mode + elif intf_type == 'loopback' or intf_type == 'svi': mode = 'layer3' return mode @@ -150,7 +158,7 @@ def get_interface_info(interface, module): if not interface.startswith('loopback'): interface = interface.capitalize() - command = 'show run | section interface.{0}'.format(interface) + command = 'show run interface {0}'.format(interface) vrf_regex = r".*vrf\s+member\s+(?P\S+).*" try: