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 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", "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", "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 On Wednesday, October 1, 2014 5:18:47 AM UTC-7, Michael DeHaan wrote: > > 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: > > - debug: var=ec2_info > > On Tue, Sep 30, 2014 at 12:45 AM, Andy Raj <[email protected] > <javascript:>> wrote: > >> 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 >> >> Below link to my playbook. >> 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", >> "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", >> "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 >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ansible Project" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/4ee1a269-2058-44d7-845b-e5b5c0b1d806%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ansible-project/4ee1a269-2058-44d7-845b-e5b5c0b1d806%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/68989a10-b5d4-404e-8718-2efe560ef22b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
