From 8f83de526c3d3e4939ad69a4a68a7f4e6534ce40 Mon Sep 17 00:00:00 2001 From: Christopher Bradley Date: Wed, 27 Jul 2022 19:49:04 +1000 Subject: [PATCH] ec2_metadata_facts - Fix read failure in ansible 2.13+ (#943) ec2_metadata_facts - Fix read failure in ansible 2.13+ SUMMARY Ansible 2.13+ changes the return conventions of fetch_url when an error occurs. Add a guard to prevent calling read which will be None. Fixes #942 ISSUE TYPE Bugfix Pull Request COMPONENT NAME ec2_metadata_facts ADDITIONAL INFORMATION Reviewed-by: Vinay Dandekar Reviewed-by: Mark Chappell --- .../fragments/943-ec2_metadata_facts-fix-NoneType-callable.yml | 2 ++ plugins/modules/ec2_metadata_facts.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/943-ec2_metadata_facts-fix-NoneType-callable.yml diff --git a/changelogs/fragments/943-ec2_metadata_facts-fix-NoneType-callable.yml b/changelogs/fragments/943-ec2_metadata_facts-fix-NoneType-callable.yml new file mode 100644 index 00000000000..86ce04f8166 --- /dev/null +++ b/changelogs/fragments/943-ec2_metadata_facts-fix-NoneType-callable.yml @@ -0,0 +1,2 @@ +bugfixes: +- ec2_metadata_facts - fix ``'NoneType' object is not callable`` exception when using Ansible 2.13+ (https://github.com/ansible-collections/amazon.aws/issues/942). diff --git a/plugins/modules/ec2_metadata_facts.py b/plugins/modules/ec2_metadata_facts.py index ae298ea18c1..91f7860eeaf 100644 --- a/plugins/modules/ec2_metadata_facts.py +++ b/plugins/modules/ec2_metadata_facts.py @@ -477,7 +477,7 @@ def _fetch(self, url): if info.get('status') not in (200, 404): # fail out now self.module.fail_json(msg='Failed to retrieve metadata from AWS: {0}'.format(info['msg']), response=info) - if response: + if response and info['status'] < 400: data = response.read() else: data = None