Skip to content

Commit

Permalink
Update tag retrieval function
Browse files Browse the repository at this point in the history
  • Loading branch information
hakbailey committed Nov 21, 2024
1 parent f6ea069 commit 20eb1cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions plugins/modules/ec2_metadata_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 20eb1cb

Please sign in to comment.