diff --git a/plugins/modules/ec2_metadata_facts.py b/plugins/modules/ec2_metadata_facts.py index a33ab6a731..3eec3f80ec 100644 --- a/plugins/modules/ec2_metadata_facts.py +++ b/plugins/modules/ec2_metadata_facts.py @@ -653,11 +653,12 @@ def fetch_session_token(self, uri_token): token_data = None return to_text(token_data) - def get_instance_tags(self, tag_keys): + def get_instance_tags(self, tag_keys, data): tags = {} for key in tag_keys: - value = self._fetch("{}/{}".format(self.uri_instance_tags, key)) - tags[key] = value + value = data.get("ansible_ec2_tags_instance_{}".format(key)) + if value is not None: + tags[key] = value return tags def run(self): @@ -677,7 +678,7 @@ def run(self): instance_tags_keys = instance_tags_keys.split("\n") if instance_tags_keys != "None" else [] data[self._prefix % "instance_tags_keys"] = instance_tags_keys - instance_tags = self.get_instance_tags(instance_tags_keys) + instance_tags = self.get_instance_tags(instance_tags_keys, data) data[self._prefix % "instance_tags"] = instance_tags # Maintain old key for backwards compatibility diff --git a/tests/integration/targets/ec2_metadata_facts/playbooks/test_metadata.yml b/tests/integration/targets/ec2_metadata_facts/playbooks/test_metadata.yml index 512cbabd1f..d0787f1324 100644 --- a/tests/integration/targets/ec2_metadata_facts/playbooks/test_metadata.yml +++ b/tests/integration/targets/ec2_metadata_facts/playbooks/test_metadata.yml @@ -15,6 +15,7 @@ - ansible_ec2_user_data == "None" - ansible_ec2_instance_tags is defined - ansible_ec2_instance_tags | length == 3 + - ansible_ec2_instance_tags.snake_case_key == "a_snake_case_value" - ansible_ec2_instance_tags_keys is defined - ansible_ec2_instance_tags_keys | length == 3