# Variables between tasksand errors between Debian and Mac OS

**URL:** <https://forum.ansible.com/t/variables-between-tasksand-errors-between-debian-and-mac-os/16853>\
**Category:** Ansible Project\
**Created:** [November 22, 2014, 9:51pm UTC](https://forum.ansible.com/t/variables-between-tasksand-errors-between-debian-and-mac-os/16853 "2014-11-22T21:51:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adele\_Dazim](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Adele\_Dazim](https://forum.ansible.com/u/Adele_Dazim)\
**Post date:** [November 22, 2014, 9:51pm UTC](https://forum.ansible.com/t/variables-between-tasksand-errors-between-debian-and-mac-os/16853/1 "2014-11-22T21:51:44Z")

</div>

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](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]

`

---

<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:** [November 24, 2014, 10:45pm UTC](https://forum.ansible.com/t/variables-between-tasksand-errors-between-debian-and-mac-os/16853/2 "2014-11-24T22:45:39Z")

</div>

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