From 20eb1cb8ca9579ce21262ca4994c734d6f7bfe97 Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Thu, 21 Nov 2024 11:29:50 -0500 Subject: [PATCH] Update tag retrieval function --- plugins/modules/ec2_metadata_facts.py | 9 +++++---- .../ec2_metadata_facts/playbooks/test_metadata.yml | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) 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