From dec1953cf7ee6cfe7c92163497b31116e6316003 Mon Sep 17 00:00:00 2001 From: Nilashish Chakraborty Date: Wed, 17 Jun 2020 23:22:46 +0530 Subject: [PATCH] Fix for vdc with no interface in N7K (https://github.com/ansible-collections/cisco.nxos/pull/68) (#69806) Fix for vdc with no interface in N7K Reviewed-by: Nilashish Chakraborty https://github.com/NilashishC Signed-off-by: NilashishC Add changelog Co-authored-by: praveenramoorthy <62758226+praveenramoorthy@users.noreply.github.com> --- changelogs/fragments/fix_nxos_facts_with_vdc.yaml | 3 +++ .../network/nxos/facts/legacy/base.py | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/fix_nxos_facts_with_vdc.yaml diff --git a/changelogs/fragments/fix_nxos_facts_with_vdc.yaml b/changelogs/fragments/fix_nxos_facts_with_vdc.yaml new file mode 100644 index 00000000000..3f29cb13da1 --- /dev/null +++ b/changelogs/fragments/fix_nxos_facts_with_vdc.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fix nxos_facts with VDC having no interfaces (https://github.com/ansible-collections/cisco.nxos/pull/68). diff --git a/lib/ansible/module_utils/network/nxos/facts/legacy/base.py b/lib/ansible/module_utils/network/nxos/facts/legacy/base.py index bd8bd22cfd3..828440d314d 100644 --- a/lib/ansible/module_utils/network/nxos/facts/legacy/base.py +++ b/lib/ansible/module_utils/network/nxos/facts/legacy/base.py @@ -252,7 +252,12 @@ class Interfaces(FactsBase): def populate_structured_interfaces(self, data): interfaces = dict() - for item in data['TABLE_interface']['ROW_interface']: + data = data["TABLE_interface"]["ROW_interface"] + + if isinstance(data, dict): + data = [data] + + for item in data: name = item['interface'] intf = dict() @@ -604,8 +609,12 @@ class Legacy(FactsBase): def parse_structured_interfaces(self, data): objects = list() - for item in data['TABLE_interface']['ROW_interface']: - objects.append(item['interface']) + data = data["TABLE_interface"]["ROW_interface"] + if isinstance(data, dict): + objects.append(data["interface"]) + elif isinstance(data, list): + for item in data: + objects.append(item["interface"]) return objects def parse_structured_vlans(self, data):