From c269898a50ade92f7e62607ff9e25c05d7f37ffd Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sat, 8 Oct 2022 03:16:18 +0200 Subject: [PATCH] Fix AttributeError when running ec2_metadata_facts (#1138) Fix AttributeError when running ec2_metadata_facts SUMMARY Prior to 5.0.0 we caught "Exception" within fetch, this was limited to json.JSONDecodeError, however it looks like we also needed to catch AttributeError for non-dict JSON ISSUE TYPE Bugfix Pull Request COMPONENT NAME ec2_metadata_facts ADDITIONAL INFORMATION fixes: #1134 --- changelogs/fragments/1134-ec2_metadata_facts-AttributeError.yml | 2 ++ plugins/modules/ec2_metadata_facts.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/1134-ec2_metadata_facts-AttributeError.yml diff --git a/changelogs/fragments/1134-ec2_metadata_facts-AttributeError.yml b/changelogs/fragments/1134-ec2_metadata_facts-AttributeError.yml new file mode 100644 index 00000000000..5a836fa7407 --- /dev/null +++ b/changelogs/fragments/1134-ec2_metadata_facts-AttributeError.yml @@ -0,0 +1,2 @@ +bugfixes: +- ec2_metadata_facts - fixed ``AttributeError`` (https://github.com/ansible-collections/amazon.aws/issues/1134). diff --git a/plugins/modules/ec2_metadata_facts.py b/plugins/modules/ec2_metadata_facts.py index 5a7875e634a..754fc34a294 100644 --- a/plugins/modules/ec2_metadata_facts.py +++ b/plugins/modules/ec2_metadata_facts.py @@ -528,7 +528,7 @@ def fetch(self, uri, recurse=True): self._data['%s' % (new_uri)] = content for (key, value) in json_dict.items(): self._data['%s:%s' % (new_uri, key.lower())] = value - except json.JSONDecodeError: + except (json.JSONDecodeError, AttributeError): self._data['%s' % (new_uri)] = content # not a stringified JSON string def fix_invalid_varnames(self, data):