diff --git a/changelogs/fragments/ec2_metadata_facts_ami-launch-index.yaml b/changelogs/fragments/ec2_metadata_facts_ami-launch-index.yaml new file mode 100644 index 00000000000..8e352cc0f3c --- /dev/null +++ b/changelogs/fragments/ec2_metadata_facts_ami-launch-index.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- "ec2_metadata_facts - Avoid an exception caused by the type of the ami-launch-index field (https://github.com/ansible-collections/amazon.aws/pull/1140)." 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): diff --git a/tests/integration/targets/ec2_metadata_facts/aliases b/tests/integration/targets/ec2_metadata_facts/aliases index 13acae67556..8207e9895cf 100644 --- a/tests/integration/targets/ec2_metadata_facts/aliases +++ b/tests/integration/targets/ec2_metadata_facts/aliases @@ -1,6 +1,2 @@ -# We're dependent on AWS actually starting up the instances in a timely manner. -# This doesn't always happen... -unstable - non_local cloud/aws