From 31e348409f47931bd7ee463c348615704f6dd1e8 Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Mon, 10 Feb 2020 18:21:59 -0500 Subject: [PATCH] [stable-2.9] nxos_facts: Don't fail if faninfo isn't reported (#66866) (#66949) (cherry picked from commit bf65e7a) Co-authored-by: Nathaniel Case --- .../fragments/66866_nxos_fan_facts.yaml | 2 ++ .../network/nxos/facts/legacy/base.py | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/66866_nxos_fan_facts.yaml diff --git a/changelogs/fragments/66866_nxos_fan_facts.yaml b/changelogs/fragments/66866_nxos_fan_facts.yaml new file mode 100644 index 00000000000..7f6c2ea7727 --- /dev/null +++ b/changelogs/fragments/66866_nxos_fan_facts.yaml @@ -0,0 +1,2 @@ +bugfixes: +- "nxos_facts: Don't throw an error if faninfo is not reported." 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 4f7d118bafe..bd8bd22cfd3 100644 --- a/lib/ansible/module_utils/network/nxos/facts/legacy/base.py +++ b/lib/ansible/module_utils/network/nxos/facts/legacy/base.py @@ -627,13 +627,19 @@ class Legacy(FactsBase): def parse_structured_fan_info(self, data): objects = list() - if data.get('fandetails'): - data = data['fandetails']['TABLE_faninfo']['ROW_faninfo'] - elif data.get('fandetails_3k'): - data = data['fandetails_3k']['TABLE_faninfo']['ROW_faninfo'] - else: - return objects - objects = list(self.transform_iterable(data, self.FAN_MAP)) + + for key in ("fandetails", "fandetails_3k"): + if data.get(key): + try: + data = data[key]['TABLE_faninfo']['ROW_faninfo'] + except KeyError: + # Some virtual images don't actually report faninfo. In this case, move on and + # just return an empty list. + pass + else: + objects = list(self.transform_iterable(data, self.FAN_MAP)) + break + return objects def parse_structured_power_supply_info(self, data):