# ec2.results is not being defined

**URL:** <https://forum.ansible.com/t/ec2-results-is-not-being-defined/21524>\
**Category:** Ansible Project\
**Created:** [May 23, 2016, 4:22pm UTC](https://forum.ansible.com/t/ec2-results-is-not-being-defined/21524 "2016-05-23T16:22:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_S1](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@Eric\_S1](https://forum.ansible.com/u/Eric_S1)\
**Post date:** [May 23, 2016, 4:22pm UTC](https://forum.ansible.com/t/ec2-results-is-not-being-defined/21524/1 "2016-05-23T16:22:05Z")

</div>

ansible ver=2.0.2

When I’m registering the ec2 var isn’t results suppose to be automatically defined as the results of what was registered in the variable. I’m getting this when trying to debug the ec2.results var:  
TASK [debug ec2 var] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Monday 23 May 2016 11:14:18 -0500 (0:00:38.587) 0:00:43.306 \*\*\*\*\*\*\*\*\*\*\*\*  
ok: [aaa-frs-ans-test1] =\> {  
“ec2.results”: “VARIABLE IS NOT DEFINED!”  
}  
ok: [aaa-frs-ans-test2] =\> {  
“ec2.results”: “VARIABLE IS NOT DEFINED!”  
}  
Here’s my creation task:

- hosts: ec2\_instances  
connection: local  
gather\_facts: true  
tasks:
- name: Launch Instance  
ec2:  
group\_id: “{{ hostvars[inventory\_hostname].group\_id }}”  
instance\_type: ‘t2.micro’  
image: “{{ hostvars[inventory\_hostname].image }}”  
wait: true  
region: ‘us-east-1’  
keypair: ‘QA\_KEYPAIR’  
vpc\_subnet\_id: “{{ subnet }}”  
instance\_tags: “{{ hostvars[inventory\_hostname].tags }}”  
register: ec2

They launch fine and if I debug ec2.instances I get all the info from that variable. Also when I debug just ec2 I get all the info as well. I did see though that when I debug just ec2 there isn’t a .results section but again I thought that was a default var.

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 23, 2016, 5:18pm UTC](https://forum.ansible.com/t/ec2-results-is-not-being-defined/21524/2 "2016-05-23T17:18:52Z")

</div>

Why don't you debug the var itself and look what subelements there are?

As to why there is no results subelement I have no clue...

Johannes

---

<div class="post-metadata">

**Author:** ![Eric\_S1](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@Eric\_S1](https://forum.ansible.com/u/Eric_S1)\
**Post date:** [May 23, 2016, 5:23pm UTC](https://forum.ansible.com/t/ec2-results-is-not-being-defined/21524/3 "2016-05-23T17:23:22Z")

</div>

I did that and there isn’t the results element. I’ve seen a lot of people using that, so not sure why its not being set.

---

<div class="post-metadata">

**Author:** ![Eric\_S1](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@Eric\_S1](https://forum.ansible.com/u/Eric_S1)\
**Post date:** [May 24, 2016, 5:40pm UTC](https://forum.ansible.com/t/ec2-results-is-not-being-defined/21524/4 "2016-05-24T17:40:09Z")

</div>

does anyone know or have a clue why ec2.results wouldn’t be populated?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 24, 2016, 5:43pm UTC](https://forum.ansible.com/t/ec2-results-is-not-being-defined/21524/5 "2016-05-24T17:43:09Z")

</div>

I think what you want is `ec2.instances` instead of `ec2.results`.

You will likely only have the `results` sub key if you are also using something like `with_items` or `with_subelements`. See [http://docs.ansible.com/ansible/playbooks\_loops.html#using-register-with-a-loop](http://docs.ansible.com/ansible/playbooks_loops.html#using-register-with-a-loop) for an explanation of register + looping, where it creates a `results` key.

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [May 24, 2016, 5:47pm UTC](https://forum.ansible.com/t/ec2-results-is-not-being-defined/21524/6 "2016-05-24T17:47:56Z")

</div>

> does anyone know or have a clue why ec2.results wouldn't be populated?

Random shots in the dark:

- Is 'ec2' as a variable name clashing with the module name in some way?  
&nbsp;&nbsp;What if you do 'register: foo' instead?

- What \*is\* in 'foo', if you 'debug: var=foo' it? Is it everything you'd  
&nbsp;&nbsp;expect to see \*except\* the 'results' element, or something totally different?

Actually, backing up a step: What do you expect to see in the results  
element, and why? Is the information that you're looking for somewhere  
else in the variable?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![Eric\_S1](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@Eric\_S1](https://forum.ansible.com/u/Eric_S1)\
**Post date:** [May 24, 2016, 6:15pm UTC](https://forum.ansible.com/t/ec2-results-is-not-being-defined/21524/7 "2016-05-24T18:15:52Z")

</div>

i also registered ec2\_info as a var just to play around and it has the same results but it does display: _sorry for the long output_  
ok: [aaa-frs-ans-test3] =\> {  
“ec2\_info”: {  
“changed”: true,  
“instance\_ids”: [  
“i-790418fe”  
],  
“instances”: [  
{  
“ami\_launch\_index”: “0”,  
“architecture”: “x86\_64”,  
“block\_device\_mapping”: {  
“/dev/sda1”: {  
“delete\_on\_termination”: true,  
“status”: “attached”,  
“volume\_id”: “vol-0c034fa7”  
}  
},  
“dns\_name”: “”,  
“ebs\_optimized”: false,  
“groups”: {  
“sg-7c538d04”: “fsr-allow-all”  
},  
“hypervisor”: “xen”,  
“id”: “i-790418fe”,  
“image\_id”: “ami-3683605b”,  
“instance\_type”: “t2.micro”,  
“kernel”: null,  
“key\_name”: “FSR\_DEV\_QA\_KEYPAIR”,  
“launch\_time”: “2016-05-24T18:13:10.000Z”,  
“placement”: “us-east-1a”,  
“private\_dns\_name”: “ip-10-196-135-193.ec2.internal”,  
“private\_ip”: “10.196.135.193”,  
“public\_dns\_name”: “”,  
“public\_ip”: null,  
“ramdisk”: null,  
“region”: “us-east-1”,  
“root\_device\_name”: “/dev/sda1”,  
“root\_device\_type”: “ebs”,  
“state”: “running”,  
“state\_code”: 16,  
“tags”: {  
“Env”: “Dev”,  
“Name”: “aaa-fsr-ans-test2”  
},  
“tenancy”: “default”,  
“virtualization\_type”: “hvm”  
}  
],  
“tagged\_instances”:   
}  
}  
for each of the hosts, meaning 3 hosts.

---

<div class="post-metadata">

**Author:** ![Eric\_S1](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@Eric\_S1](https://forum.ansible.com/u/Eric_S1)\
**Post date:** [May 25, 2016, 7:23pm UTC](https://forum.ansible.com/t/ec2-results-is-not-being-defined/21524/8 "2016-05-25T19:23:48Z")

</div>

Matt that makes sense. I did try ec2.instances but it is only add the first host not all three. I did do a debug on ec2 and ec2.instances and it is showing all 3 instances that I’m turning up. Any ideas on that. This is only happening on the add\_hosts module. I have a wait for ssh to come up task and ec2.instances var are giving me an ok for all three.

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [May 25, 2016, 7:36pm UTC](https://forum.ansible.com/t/ec2-results-is-not-being-defined/21524/9 "2016-05-25T19:36:23Z")

</div>

> I did try ec2.instances but it is only add the first host not all  
> three. I did do a debug on ec2 and ec2.instances and it is showing all  
> 3 instances that I'm turning up. Any ideas on that. This is only  
> happening on the add\_hosts module. I have a wait for ssh to come up  
> task and ec2.instances var are giving me an ok for all three.

I tried with this trivial playbook, and it worked fine:

&nbsp;&nbsp;- hosts: localhost  
&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myhosts: [apple, banana, cherry]  
&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug: var=myhosts  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- add\_host: name={{ item }} groups=mygroup  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: myhosts  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug: var=groups['mygroup']

I got

&nbsp;&nbsp;TASK: [debug var=groups['mygroup']]
