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

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

And my playbook is located here 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”,
“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”,
“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

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 :slight_smile:

Can you post your playbook(s)?

Here you go - https://github.com/raj-andy1/macguffin