# aws ec2 module getting error - One or more undefined variables: 'instances' is undefined

**URL:** <https://forum.ansible.com/t/aws-ec2-module-getting-error-one-or-more-undefined-variables-instances-is-undefined/16377>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [September 30, 2014, 4:45am UTC](https://forum.ansible.com/t/aws-ec2-module-getting-error-one-or-more-undefined-variables-instances-is-undefined/16377 "2014-09-30T04:45:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy\_Raj](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Andy\_Raj](https://forum.ansible.com/u/Andy_Raj)\
**Post date:** [September 30, 2014, 4:45am UTC](https://forum.ansible.com/t/aws-ec2-module-getting-error-one-or-more-undefined-variables-instances-is-undefined/16377/1 "2014-09-30T04:45:47Z")

</div>

Hello folks,

New to ansible, using version - 1.7.2. I am trying to write a play to launch an instance on AWS and install my packages on it. i need to automatically add the DNS name of the launched instance to my hosts file. But i am getting the error - One or more undefined variables: ‘instances’ is undefined

I am following the example here - [http://docs.ansible.com/guide\_aws.html](http://docs.ansible.com/guide_aws.html)

Below link to my playbook.  
[https://github.com/raj-andy1/macguffin/blob/master/aws-plays/aws-ec2.yaml](https://github.com/raj-andy1/macguffin/blob/master/aws-plays/aws-ec2.yaml)

Please help

Below is the output i am getting

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [make one instance] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [localhost]

TASK: [debug var=ec2\_info] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“ec2\_info”: {  
“changed”: true,  
“instance\_ids”: [  
“i-7e343873”  
],  
“instances”: [  
{  
“ami\_launch\_index”: “0”,  
“architecture”: “x86\_64”,  
“dns\_name”: “[ec2-54-69-18-39.us-west-2.compute.amazonaws.com](http://ec2-54-69-18-39.us-west-2.compute.amazonaws.com)”,  
“ebs\_optimized”: false,  
“hypervisor”: “xen”,  
“id”: “i-7e343873”,  
“image\_id”: “ami-b6bdde86”,  
“instance\_type”: “t1.micro”,  
“kernel”: “aki-fc37bacc”,  
“key\_name”: null,  
“launch\_time”: “2014-09-30T04:37:29.000Z”,  
“placement”: “us-west-2b”,  
“private\_dns\_name”: “ip-172-31-28-117.us-west-2.compute.internal”,  
“private\_ip”: “172.31.28.117”,  
“public\_dns\_name”: “[ec2-54-69-18-39.us-west-2.compute.amazonaws.com](http://ec2-54-69-18-39.us-west-2.compute.amazonaws.com)”,  
“public\_ip”: “54.69.18.39”,  
“ramdisk”: null,  
“region”: “us-west-2”,  
“root\_device\_name”: “/dev/sda1”,  
“root\_device\_type”: “ebs”,  
“state”: “running”,  
“state\_code”: 16,  
“virtualization\_type”: “paravirtual”  
}  
],  
“invocation”: {  
“module\_args”: “image=ami-b6bdde86 instance\_type=t1.micro region=us-west-2 wait=true”,  
“module\_name”: “ec2”  
},  
“tagged\_instances”:   
}  
}

TASK: [debug msg=“Assigned public DNS name is {{ instances.public\_dns\_name }}”] \*\*\*  
fatal: [localhost] =\> One or more undefined variables: ‘instances’ is undefined

FATAL: all hosts have already failed – aborting

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @/Users/andyr/aws-ec2.yaml.retry

localhost : ok=2 changed=1 unreachable=1 failed=0

---

<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:** [October 1, 2014, 12:18pm UTC](https://forum.ansible.com/t/aws-ec2-module-getting-error-one-or-more-undefined-variables-instances-is-undefined/16377/2 "2014-10-01T12:18:44Z")

</div>

Reading your playbook above, there’s no point at which you register into a variable called “instances”, which is the problem.

Move your debug line up and see what is in it:

---

<div class="post-metadata">

**Author:** ![Andy\_Raj](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Andy\_Raj](https://forum.ansible.com/u/Andy_Raj)\
**Post date:** [October 7, 2014, 11:01pm UTC](https://forum.ansible.com/t/aws-ec2-module-getting-error-one-or-more-undefined-variables-instances-is-undefined/16377/3 "2014-10-07T23:01:08Z")

</div>

Hi Mike

Thanks for your response. I tried to follow the example on Ansible’s website([http://docs.ansible.com/guide\_aws.html](http://www.google.com/url?q=http%3A%2F%2Fdocs.ansible.com%2Fguide_aws.html&sa=D&sntz=1&usg=AFQjCNHX6YFKKa0SgSDVv3X7j6hFXpGsOA)) but still no success. Not sure what is wrong  
Can you please help?

Playbook location - [https://github.com/raj-andy1/macguffin/blob/master/aws-plays/aws-ec2.yaml](https://github.com/raj-andy1/macguffin/blob/master/aws-plays/aws-ec2.yaml)

Thanks  
Andy

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [make one instance] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [localhost]

TASK: [debug var=ec2\_info] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“ec2\_info”: {  
“changed”: true,  
“instance\_ids”: [  
“i-25918128”  
],  
“instances”: [  
{  
“ami\_launch\_index”: “0”,  
“architecture”: “x86\_64”,  
“dns\_name”: “[ec2-54-69-33-81.us-west-2.compute.amazonaws.com](http://ec2-54-69-33-81.us-west-2.compute.amazonaws.com)”,  
“ebs\_optimized”: false,  
“hypervisor”: “xen”,  
“id”: “i-25918128”,  
“image\_id”: “ami-b6bdde86”,  
“instance\_type”: “t1.micro”,  
“kernel”: “aki-fc37bacc”,  
“key\_name”: null,  
“launch\_time”: “2014-10-07T22:57:06.000Z”,  
“placement”: “us-west-2b”,  
“private\_dns\_name”: “ip-172-31-29-210.us-west-2.compute.internal”,  
“private\_ip”: “172.31.29.210”,  
“public\_dns\_name”: “[ec2-54-69-33-81.us-west-2.compute.amazonaws.com](http://ec2-54-69-33-81.us-west-2.compute.amazonaws.com)”,  
“public\_ip”: “54.69.33.81”,  
“ramdisk”: null,  
“region”: “us-west-2”,  
“root\_device\_name”: “/dev/sda1”,  
“root\_device\_type”: “ebs”,  
“state”: “running”,  
“state\_code”: 16,  
“virtualization\_type”: “paravirtual”  
}  
],  
“invocation”: {  
“module\_args”: “image=ami-b6bdde86 instance\_type=t1.micro region=us-west-2 wait=true”,  
“module\_name”: “ec2”  
},  
“tagged\_instances”:   
}  
}

TASK: [debug var=item with\_items:ec2\_info.instance\_ids] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> (item={{ item }}) =\> {  
“item”: “{{ item }}”  
}

TASK: [debug msg=“Assigned public DNS name is {{ item.dns\_name }}” with\_items:ec2\_info.instances] \*\*\*  
fatal: [localhost] =\> One or more undefined variables: ‘item’ is undefined

FATAL: all hosts have already failed – aborting

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @/Users/andyr/aws-ec2.yaml.retry

localhost : ok=3 changed=1 unreachable=1 failed=0
