# cleaned up variables in 1.2

**URL:** <https://forum.ansible.com/t/cleaned-up-variables-in-1-2/12739>\
**Category:** Ansible Project\
**Created:** [April 30, 2013, 5:08am UTC](https://forum.ansible.com/t/cleaned-up-variables-in-1-2/12739 "2013-04-30T05:08:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [April 30, 2013, 5:08am UTC](https://forum.ansible.com/t/cleaned-up-variables-in-1-2/12739/1 "2013-04-30T05:08:38Z")

</div>

Can somebody explain the new cleaned up variables? Maybe add something to the docs...

The new docs only mention when:, and I have a case that works with:  
when\_string: sometask.rc != 0

but I cannot figure out the right incantation of "when:" to make it work...

Thanks.

---

<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 30, 2013, 12:31pm UTC](https://forum.ansible.com/t/cleaned-up-variables-in-1-2/12739/2 "2013-04-30T12:31:03Z")

</div>

In 1.2, there is no need for “when\_\*” anymore. The new way is simply:

when: sometask.rc != 0

Still compatible for legacy reasons, since that was legal in 1.1:

when\_integer: ${sometask.rc} != 0

Note that the “.rc” is a integer, not a string, so when\_string will not work unless you quoted the 0, like:

when\_integer: ${sometask.rc} != ‘0’

As I agree both of these forms are terrible (a result of fighting the inclusion of Jinja2 in Ansible for too long, I think!), that’s the reason for the new unified “when” simplicity.

The expression given to when is any Python expression legal to Jinja2 (so no list comprehensions) and is actually evaluated by the template Engine, but {{ foo }} style dereferences are unnecessary to keep things clean.

Since this is so much cleaner, the 1.2 docs only mention these forms, so folks can start standardizing on them.

I still have to update examples/playbooks/\* in the source checkout do to the same.

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [April 30, 2013, 2:33pm UTC](https://forum.ansible.com/t/cleaned-up-variables-in-1-2/12739/3 "2013-04-30T14:33:21Z")

</div>

I found the issue. I had a dash in my variable name. This worked fine with "when\_string", but not with "when".

---

<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 30, 2013, 2:59pm UTC](https://forum.ansible.com/t/cleaned-up-variables-in-1-2/12739/4 "2013-04-30T14:59:02Z")

</div>

Yep, dashes shouldn’t be used in variable names.

We should document this and consider enforcing it with at least a warning.

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [April 30, 2013, 7:32pm UTC](https://forum.ansible.com/t/cleaned-up-variables-in-1-2/12739/5 "2013-04-30T19:32:27Z")

</div>

What are the exact restrictions?  
Letter, number, undersign? Any other acceptable characters?

---

<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 30, 2013, 7:36pm UTC](https://forum.ansible.com/t/cleaned-up-variables-in-1-2/12739/6 "2013-04-30T19:36:36Z")

</div>

Letter number underscore, starts with letter.

Things valid in Jinja2 need to be valid Python variables, which is pretty much the rule for most programming systems (some languages may have different rules but I can’t recall any offhand)
