# Variables not working in playbook

**URL:** <https://forum.ansible.com/t/variables-not-working-in-playbook/12966>\
**Category:** Ansible Project\
**Created:** [June 15, 2013, 2:30pm UTC](https://forum.ansible.com/t/variables-not-working-in-playbook/12966 "2013-06-15T14:30:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 15, 2013, 2:30pm UTC](https://forum.ansible.com/t/variables-not-working-in-playbook/12966/1 "2013-06-15T14:30:35Z")

</div>

Dear list,

I am a bit stomped. I have the following test playbook:

&nbsp;&nbsp;% cat test.yml  
&nbsp;&nbsp;- hosts: localhost  
&nbsp;&nbsp;&nbsp;&nbsp;gather\_facts: yes  
&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: test  
&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug: msg=$msg  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug: msg=$ansible\_fqdn

You'd think this should yield two debug messages with 'test' and  
'localhost', right?

Well, no. Wrong:

&nbsp;&nbsp;% ansible-playbook test.yml  
&nbsp;&nbsp;PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

&nbsp;&nbsp;GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
&nbsp;&nbsp;ok: [localhost]

&nbsp;&nbsp;TASK: [debug msg=$msg] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
&nbsp;&nbsp;ok: [localhost] =\> {"msg": "$msg"}

&nbsp;&nbsp;TASK: [debug msg=$ansible\_fqdn] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
&nbsp;&nbsp;ok: [localhost] =\> {"msg": "$ansible\_fqdn"}

&nbsp;&nbsp;PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
&nbsp;&nbsp;localhost : ok=3 changed=0 unreachable=0 failed=0

Could someone please tell me what is going on?

&nbsp;&nbsp;% ansible-playbook --version  
&nbsp;&nbsp;ansible-playbook 1.3 (devel 0bd5fe9951) last updated 2013/06/15 16:06:49 (GMT +200)

Thanks,

---

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 15, 2013, 3:24pm UTC](https://forum.ansible.com/t/variables-not-working-in-playbook/12966/2 "2013-06-15T15:24:18Z")

</div>

also sprach martin f krafft \<madduck@madduck.net\> [2013.06.15.1630 +0200]:

> &nbsp;&nbsp;&nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug: msg=$msg  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug: msg=$ansible\_fqdn
> 
> You'd think this should yield two debug messages with 'test' and  
> 'localhost', right?

It does, unless you set legacy\_playbook\_variables=no in ansible.cfg.  
Doh!

Sorry for the noise.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [June 15, 2013, 3:31pm UTC](https://forum.ansible.com/t/variables-not-working-in-playbook/12966/3 "2013-06-15T15:31:17Z")

</div>

If it makes you feel any better I had the exact same issue, I had set it the day before to test and spent 2h trying to figure out the next day when all my older playbooks were breaking.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 15, 2013, 4:13pm UTC](https://forum.ansible.com/t/variables-not-working-in-playbook/12966/4 "2013-06-15T16:13:04Z")

</div>

Ok, not a bug 🙂
