It looks like your variable is defined to the localhost action and then is
not defined when talking to your ec2_hosts.



On Sat, Nov 22, 2014 at 4:51 PM, Adele Dazim <[email protected]> wrote:

> Hi All,
>
> I'm using a playbook to create an instance. Essentially, I've modified the
> code snippet on example 4 here -> http://docs.ansible.com/guide_aws.html
>
> From the command_line, I pass in a variable "instance_name", which I use
> to set the tags for the EC2 instance and the hostname for the instance I
> just created.
>
> The below code snippet works fine on Mac (Ansible 1.7.2), but fails on
> Debian 8.0 with the same version of Ansible 1.7.2.
>
> What am I doing wrong? Or is this something with the code?
>
> - hosts: localhost
>
>   connection: local
>
>   gather_facts: False
>
>   vars:
>       instance_name: "somename"
>   -tasks:
>
> --snipped--
> --snipped--
>
> # Connect to the node and gather facts, including the instance-id. These
> facts
> # are added to inventory hostvars for the duration of the playbook's
> execution
> # Typical "provisioning" tasks would go in this playbook.
>
> - hosts: ec2hosts
>   gather_facts: True
>   user: admin
>   sudo: True
>
>   tasks:
>     # fetch instance data from the metadata servers in ec2
>     - ec2_facts:
>
>     # show all known facts for this host
>     - debug: var=hostvars[inventory_hostname]
>
>     # just show the instance-id
>     - debug: msg="{{
> hostvars[inventory_hostname]['ansible_ec2_instance_id'] }}"
>
>     - name: set hostname to {{ instance_name }}
>       hostname:
>         name: "{{ instance_name }}"
>
>
> The error I get on debian is:
>
> TASK: [set hostname to {{ instance_name }}]
> ***********************************
>
>
> fatal: [54.xx.xx.xx] => One or more undefined variables: 'instance_name'
> is undefined
>
> FATAL: all hosts have already failed -- aborting
>
> PLAY RECAP
> ********************************************************************
>
>
> On the Mac (Yosemite), this part goes without any incident:
>
> TASK: [set hostname to somename]
> *************************************************
>
> changed: [54.xx.xx.xx]
>
>
>  --
> 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/e4480e53-547b-4f74-a519-879213793633%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/e4480e53-547b-4f74-a519-879213793633%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/CA%2BnsWgzuLNcn%3D7JpeKvjJPA65Ry7E%3DXxeDvgM5nNjA-sdo3g%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to