# ec2 module returning "One or more undefined variables: 'item' is undefined"

**URL:** <https://forum.ansible.com/t/ec2-module-returning-one-or-more-undefined-variables-item-is-undefined/16383>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [September 30, 2014, 4:03pm UTC](https://forum.ansible.com/t/ec2-module-returning-one-or-more-undefined-variables-item-is-undefined/16383 "2014-09-30T16:03:51Z")\
**Posts on this page:** 4\
**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:03pm UTC](https://forum.ansible.com/t/ec2-module-returning-one-or-more-undefined-variables-item-is-undefined/16383/1 "2014-09-30T16:03:51Z")

</div>

Hello Fellow ansible users,

I am new to ansible, using version 1.7.2 on Mac OSx. I am trying to launch aws instances and install our code on them as part of an automated deployment process.  
I am following this example [http://docs.ansible.com/guide\_aws.html](http://docs.ansible.com/guide_aws.html)

And my playbook is located here [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)

I need to launch the instance and add the instance name into my hosts file. however it is failing with this error -“One or more undefined variables: ‘item’ is undefined”  
I have tried changing {{ item.public\_dns\_name }} to {{ instances.public\_dns\_name }} but no luck.

Can someone please help me out?

Thanks in advance for the help

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

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

TASK: [debug var=ec2\_info] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“ec2\_info”: {  
“changed”: true,  
“instance\_ids”: [  
“i-777d727a”  
],  
“instances”: [  
{  
“ami\_launch\_index”: “0”,  
“architecture”: “x86\_64”,  
“dns\_name”: “[ec2-54-69-175-101.us-west-2.compute.amazonaws.com](http://ec2-54-69-175-101.us-west-2.compute.amazonaws.com)”,  
“ebs\_optimized”: false,  
“hypervisor”: “xen”,  
“id”: “i-777d727a”,  
“image\_id”: “ami-b6bdde86”,  
“instance\_type”: “t1.micro”,  
“kernel”: “aki-fc37bacc”,  
“key\_name”: null,  
“launch\_time”: “2014-09-30T15:51:25.000Z”,  
“placement”: “us-west-2b”,  
“private\_dns\_name”: “ip-172-31-23-4.us-west-2.compute.internal”,  
“private\_ip”: “172.31.23.4”,  
“public\_dns\_name”: “[ec2-54-69-175-101.us-west-2.compute.amazonaws.com](http://ec2-54-69-175-101.us-west-2.compute.amazonaws.com)”,  
“public\_ip”: “54.69.175.101”,  
“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 {{ item.public\_dns\_name }}”] \*\*\*\*  
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=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:23pm UTC](https://forum.ansible.com/t/ec2-module-returning-one-or-more-undefined-variables-item-is-undefined/16383/2 "2014-10-01T12:23:46Z")

</div>

The ec2 module is actually not returning this as an error, where you have it, there is no global named “item”.

This error message is appropriate.

You’ll need to debug a variable that’s actually in scope 🙂

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [November 14, 2014, 4:24pm UTC](https://forum.ansible.com/t/ec2-module-returning-one-or-more-undefined-variables-item-is-undefined/16383/3 "2014-11-14T16:24:32Z")

</div>

Can you post your playbook(s)?

---

<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:** [November 14, 2014, 6:02pm UTC](https://forum.ansible.com/t/ec2-module-returning-one-or-more-undefined-variables-item-is-undefined/16383/4 "2014-11-14T18:02:13Z")

</div>

Here you go - [https://github.com/raj-andy1/macguffin](https://github.com/raj-andy1/macguffin)
