# Various variable improvements made recently

**URL:** <https://forum.ansible.com/t/various-variable-improvements-made-recently/12661>\
**Category:** Ansible Project\
**Created:** [April 11, 2013, 1:36pm UTC](https://forum.ansible.com/t/various-variable-improvements-made-recently/12661 "2013-04-11T13:36:33Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [April 11, 2013, 1:36pm UTC](https://forum.ansible.com/t/various-variable-improvements-made-recently/12661/1 "2013-04-11T13:36:33Z")

</div>

Hi everyone,

I just pushed a lot of commits I made on the plane last night that further upgrade the usage of the “new” 1.2 variable/conditional syntax, as detailed here:

[https://github.com/ansible/ansible/blob/devel/examples/playbooks/upgraded\_vars.yml](https://github.com/ansible/ansible/blob/devel/examples/playbooks/upgraded_vars.yml)

Notice that with\_items can now be fed the name of a variable, or even a Python expression, and it just works, no need for $foo or {{ }} at all. There are also various improvements to corner cases, so I’d consider this ready for full usage now.

There’s also a lot of other assorted cleanup.

My plan is to make the documentation for 1.2 all use the {{ new.way }}, and then determine if there is a future date where we may want to deprecate the $old.{way}

I think streamlining the docs will end a lot of user confusion.

Currently it internally flags deprecation warnings but doesn’t print them, I suspect we may choose to do the same with “when\_” and only\_if as well.

I also fixed some issues with parameterized playbook includes.

---

<div class="post-metadata">

**Author:** ![GW1](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@GW1](https://forum.ansible.com/u/GW1)\
**Post date:** [April 11, 2013, 2:49pm UTC](https://forum.ansible.com/t/various-variable-improvements-made-recently/12661/2 "2013-04-11T14:49:50Z")

</div>

Hi,

I find myself doing a constant mistake when using the new 1.2 variables, namely:

something: {{ var1 }}

That is treated as JSON inside YAML syntax instead of something starting with a variable.

Although this breaks the YAML syntax, there could be a check if it starts with “{{” and contains somewhere “}}”, eg. with regex: ‘^{{[^{]+}}’.

Greetings,  
gw

---

<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:** [April 11, 2013, 2:50pm UTC](https://forum.ansible.com/t/various-variable-improvements-made-recently/12661/3 "2013-04-11T14:50:58Z")

</div>

This is why in the case of

with\_items: foo

you don’t have to surround it in {{ }} anymore.

What was the case in which you personally encountered it?

---

<div class="post-metadata">

**Author:** ![GW1](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@GW1](https://forum.ansible.com/u/GW1)\
**Post date:** [April 11, 2013, 3:29pm UTC](https://forum.ansible.com/t/various-variable-improvements-made-recently/12661/4 "2013-04-11T15:29:32Z")

</div>

Hi,

Now that with\_ and when\_ work this are the only (maybe not the best) use cases:

---- hosts: all  
vars:

- cmd: /bin/echo
- var: {{ cmd }}  
tasks:
- command: {{ cmd }} foo bar
- shell: {{ item }}  
with\_items:
- echo first

A solution without explicitly putting everything that is not needed into strings:

---- hosts: all  
vars:

- cmd: /bin/echo
- var: ‘{{ cmd }}’  
tasks:
- action: command {{ cmd }} foo bar
- action: shell {{ item }}  
with\_items:
- echo first

Greetings,  
gw

---

<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:** [April 11, 2013, 4:02pm UTC](https://forum.ansible.com/t/various-variable-improvements-made-recently/12661/5 "2013-04-11T16:02:48Z")

</div>

Yep, I had written a preprocessor for this yesterday but I think that’s a dangerous trap as someone will want to read the YAML later when it’s not valid.

As such, $cmd still work in this case, I don’t think I’m going to remove the basic variable referencing like this.

My other thought was to change the Jinja2 delimiter for playbooks so it’s different than what is used in templates, though that also has downsides.
