# Variable expansion and tags with the EC2 module

**URL:** <https://forum.ansible.com/t/variable-expansion-and-tags-with-the-ec2-module/14464>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [January 30, 2014, 7:39pm UTC](https://forum.ansible.com/t/variable-expansion-and-tags-with-the-ec2-module/14464 "2014-01-30T19:39:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Gargan](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Stephen\_Gargan](https://forum.ansible.com/u/Stephen_Gargan)\
**Post date:** [January 30, 2014, 7:39pm UTC](https://forum.ansible.com/t/variable-expansion-and-tags-with-the-ec2-module/14464/1 "2014-01-30T19:39:37Z")

</div>

I’m deploying a system to an number of machines in EC2 and am seeing some weird behavior with variable expansion

I have group\_vars where I define a target version for my system and versions for components a, b and c. Typically a, b and c use the same target version, but I need the ability to override each  
with a different version. I’ve been modelling this as a varaibles file all in group\_vars containing

target\_version: 12345  
a\_version: “{{target\_version}}”  
b\_version: “{{target\_version}}”  
c\_version: “{{target\_version}}”

For the most part this works well, the following play

- hosts: localhost  
connection: local  
tasks:
- debug: var=target\_version
- debug: var=a\_version

expands as expected to

TASK: [debug var=target\_version] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1] =\> {  
“target\_version”: “12345”  
}

TASK: [debug var=a\_version] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1] =\> {  
“a\_version”: “12345”  
}

However when I spin up my EC2 instance and retrieve the facts,

- hosts: ec2cluster  
gather\_facts: True  
user: ansible  
sudo: True  
tasks:

- ec2\_facts:

- debug: var=hostvars[inventory\_hostname]

these appear unexpanded as follows

“hostvars[inventory\_hostname]”: {  
“a\_version”: “{{target\_version}}”,

Also I pass in a variable containing instance tags that I’d like to add to the machine. I see that these get to the instance in the AWS console, but are not returned as ec2 facts like I’d have expected.

Are these bugs, or am I doing something wrong?

thanks,

Steve.

---

<div class="post-metadata">

**Author:** ![esteevio](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@esteevio](https://forum.ansible.com/u/esteevio)\
**Post date:** [January 30, 2014, 9:50pm UTC](https://forum.ansible.com/t/variable-expansion-and-tags-with-the-ec2-module/14464/2 "2014-01-30T21:50:43Z")

</div>

For the tags at least, it seems these get returned as part hostvar group\_names formatted tag\_name\_value e.g. tag\_sometag\_somevalue.
