# Variable interpolation problem in playbook

**URL:** <https://forum.ansible.com/t/variable-interpolation-problem-in-playbook/13295>\
**Category:** Ansible Project\
**Created:** [August 13, 2013, 8:12pm UTC](https://forum.ansible.com/t/variable-interpolation-problem-in-playbook/13295 "2013-08-13T20:12:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark1](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@Mark1](https://forum.ansible.com/u/Mark1)\
**Post date:** [August 13, 2013, 8:12pm UTC](https://forum.ansible.com/t/variable-interpolation-problem-in-playbook/13295/1 "2013-08-13T20:12:37Z")

</div>

I have the following playbook:

----------- start --------------

# Launches a CF stack and provisions the instance as the specified role

---

<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:** [August 13, 2013, 8:24pm UTC](https://forum.ansible.com/t/variable-interpolation-problem-in-playbook/13295/2 "2013-08-13T20:24:03Z")

</div>

So it’s hard to tell anything from this example as we haven’t seen all of the files referenced. Could just be a typo somewhere. I do recommend that people try 1.3, you can enable undefined variable warnings in ansible.cfg, which will soon be the default.

I also highly recommend standarding on new style variable syntax and dropping the legacy form, which is required to use that variable detection.

{{ foo }}

---

<div class="post-metadata">

**Author:** ![Mark1](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@Mark1](https://forum.ansible.com/u/Mark1)\
**Post date:** [August 13, 2013, 8:27pm UTC](https://forum.ansible.com/t/variable-interpolation-problem-in-playbook/13295/3 "2013-08-13T20:27:41Z")

</div>

I can in fact work around this by only adding the new hosts to a single host group and passing that through as ‘hosts’, but if it’s a bug, it’s still worth fixing.

---

<div class="post-metadata">

**Author:** ![Mark1](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@Mark1](https://forum.ansible.com/u/Mark1)\
**Post date:** [August 13, 2013, 8:32pm UTC](https://forum.ansible.com/t/variable-interpolation-problem-in-playbook/13295/4 "2013-08-13T20:32:36Z")

</div>

The important part is that in the debug message, $role is interpolated:

debug msg=“tag\_Name\_webserver”

but when it passes it through to the included playbook via “hosts=tag\_Name\_$role:&tag\_env\_$env” only $env is interpolated, and $role just becomes the string ‘role’.

I’m running against devel btw.

Also, what are the benefits of $var vs {{ var }}? The docs don’t seem to make much of a distinction.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 13, 2013, 8:37pm UTC](https://forum.ansible.com/t/variable-interpolation-problem-in-playbook/13295/5 "2013-08-13T20:37:40Z")

</div>

The docs don’t even mention ${old\_stuff} anymore at all, which is why they don’t make a distinction, but I suspect you have confused the legacy parser.

I’ll help with questions on new style variables but not old style ones anymore.

Main thing is getting nested data out of the old form is completely impossible, whereas using Jinja2 inline is much more powerful.

---

<div class="post-metadata">

**Author:** ![Mark1](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@Mark1](https://forum.ansible.com/u/Mark1)\
**Post date:** [August 13, 2013, 8:47pm UTC](https://forum.ansible.com/t/variable-interpolation-problem-in-playbook/13295/6 "2013-08-13T20:47:07Z")

</div>

> The docs don’t even mention ${old\_stuff} anymore at all, which is why they don’t make a distinction, but I suspect you have confused the legacy parser.

[http://www.ansibleworks.com/docs/playbooks.html#vars-section](http://www.ansibleworks.com/docs/playbooks.html#vars-section) refers to ${varname}. I’ll see whether changing to {{ var }} helps.

---

<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:** [August 14, 2013, 12:35am UTC](https://forum.ansible.com/t/variable-interpolation-problem-in-playbook/13295/7 "2013-08-14T00:35:45Z")

</div>

I’ll file a doc ticket to make it clear ${var} is less recommended.

Thanks!
