# using ec2-create module output as variable

**URL:** <https://forum.ansible.com/t/using-ec2-create-module-output-as-variable/15562>\
**Category:** Ansible Project\
**Created:** [June 27, 2014, 8:38am UTC](https://forum.ansible.com/t/using-ec2-create-module-output-as-variable/15562 "2014-06-27T08:38:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serkan\_C](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Serkan\_C](https://forum.ansible.com/u/Serkan_C)\
**Post date:** [June 27, 2014, 8:38am UTC](https://forum.ansible.com/t/using-ec2-create-module-output-as-variable/15562/1 "2014-06-27T08:38:46Z")

</div>

Hi,  
I would like to use ec2-create module outputs as variable and pass it to other roles, this is playbook structure;

---

<div class="post-metadata">

**Author:** ![dan.vaida](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@dan.vaida](https://forum.ansible.com/u/dan.vaida)\
**Post date:** [June 27, 2014, 6:29pm UTC](https://forum.ansible.com/t/using-ec2-create-module-output-as-variable/15562/2 "2014-06-27T18:29:00Z")

</div>

Instead of using set\_fact, I would suggest

`

- debug var={{ item.id }}  
with\_items: ec2\_create\_result.instances  
`

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 29, 2014, 1:03am UTC](https://forum.ansible.com/t/using-ec2-create-module-output-as-variable/15562/3 "2014-06-29T01:03:55Z")

</div>

set\_fact is basically around to allow cases where you get an integer back from something and something else needs that value multiplied by 10 or 3 or something. It’s a very niche module, that somehow gets overused.

It also really likes to mangle types unless you use it in complex\_args mode like so:

- set\_fact:  
x: y.foo

So it doesn’t go through stringification.

Anyway…“I would like to use ec2-create module outputs as variable and pass it to other roles, this is playbook structure;”

In this case, just do the register, and ec2\_create\_result could be referenced in your other roles, and that would likely be easiest.

---

<div class="post-metadata">

**Author:** ![Serkan\_C](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Serkan\_C](https://forum.ansible.com/u/Serkan_C)\
**Post date:** [July 10, 2014, 10:13am UTC](https://forum.ansible.com/t/using-ec2-create-module-output-as-variable/15562/4 "2014-07-10T10:13:28Z")

</div>

I’ve used this;

action:  
module: ec2  
image: “{{ aws\_ami }}”  
instance\_type: “{{ aws\_instance\_type }}”  
state: present  
wait: yes  
ec2\_access\_key: “{{ ec2\_access\_key }}”  
ec2\_secret\_key: “{{ ec2\_secret\_key }}”  
register: ec2\_create\_result

…

debug: var={{ec2\_create\_result.instances[0].public\_ip

Thanks all.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 10, 2014, 12:25pm UTC](https://forum.ansible.com/t/using-ec2-create-module-output-as-variable/15562/5 "2014-07-10T12:25:38Z")

</div>

The “var” param on the debug module is used to output specific variables and does not take a Jinja2 template as a parameter, as what you are then feeding to “var” is the result of the template evaluation - templating happens first.

It seems you want:

debug: msg=“My value is {{ foo }}”
