Quantcast
Channel: Active questions tagged amazon-ec2 - Stack Overflow
Viewing all articles
Browse latest Browse all 29425

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

$
0
0

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:

  • name: get metadataamazon.aws.ec2_metadata_facts:register: ec2_facts

  • name: set URL var based on EC2 tagset_fact:new_var: "{{ ansible_ec2_tags_instance_mytagname }}"

    tags:

    • testssl

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).


Viewing all articles
Browse latest Browse all 29425

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>