Variables between tasksand errors between Debian and Mac OS

21 views
Skip to first unread message

Adele Dazim

unread,
Nov 22, 2014, 4:51:44 PM11/22/14
to ansible...@googlegroups.com
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]


Michael DeHaan

unread,
Nov 24, 2014, 5:45:45 PM11/24/14
to ansible...@googlegroups.com
It looks like your variable is defined to the localhost action and then is not defined when talking to your ec2_hosts.



--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e4480e53-547b-4f74-a519-879213793633%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages