Daniel Owen
Daniel Owen

Reputation: 1

how to access EC2 tags using ansible module amazon.aws.ec2_metadata_facts

I found many posts on how to access and store an EC2 tag (using EC2 metadata) into a variable in ansible. I was not able to get most of them to work, however I was able to make it work using a variable name that I can't find documented anywhere. In my code below, I use the set_fact module to store the tag name in a variable in a way that I can't seem to find documented anywhere, so I am wondering why it worked - specifically I used a variable naming format of: ansible_ec2_tags_instance_

Here is a brief example of the code that I used in the playbook. In this yaml code example, I am using a tag name of mytagname for illustration purposes:

This worked. Also, I did some additional testing and found that I can make this work with most of my tag names UNLESS they have a '-' in the name i.e. these work: mytag, my_tag but this DOESN'T work: my-tag

Is this documented somewhere that I am missing?

I was hoping to find a simple way to access the hostvars variables provided by the EC2 instance (with the 'allow tags in instance metadata' setting enabled on the EC2 instance).

Upvotes: 0

Views: 93

Answers (0)

Related Questions