Devel branch update -- pending death to old style variables! We now have references and preserved types!

Hi everyone!

AWESOME NEWS #1 — one of the frequent complaints about the using variables from Jinja2 like {{ foo }} versus the old ways ${x} was that it was hard to make one thing reference another, and it often “ate” types as it converted things to strings. No more!

AWESOME NEWS #2 – the unit tests are now 50% faster. That probably means something for real life too :slight_smile:

How’d this happen? New on the 1.4 devel branch (scheduled for release towards the middle/end of November), I took a lot of legacy template code out back and shot it.

The following SUPER PATHOLOGICAL example is now functional. I’ll warn you, nobody should write playbooks like this, as it gives all of us a bad name, and I’ll flog anyone who does. However, it’s a nice proof of concept that many difficulties in variables referencing variables and being recursive in odd ways is now functional!

  • hosts: all
    vars:
    cat: yes
    x: 42
    decoded:
    home: “/usr/bob”
    moo: yes
    xyz: “{{ decoded.home }}”
    glorp: “{{ raz }}”
    fish: “{{ decoded.xyz }}”
    baz: “{{ fish }}”
    raz: “{{ decoded.moo }}”

tasks:

  • debug: msg=“it is true $x”
    when: decoded.glorp

  • debug: msg=“{{ baz }}”

in 1.4 you might as well say this:

  • debug: var=baz

  • template: src=/tmp/foo dest=/tmp/bar

In the above example

decoded.glorp is the value of raz
raz has the value decoded.moo
decoded.moo is a boolean

baz has the value of fish

fish has the value of decoded.xyz
decoded.xyz has a reference inside the same structure to the value of decoded.home
decoded.home is /usr/bob

WHOA, THAT’S CRAZY!

So let’s rejoice, as a result, we are moving the deprecation plan for legacy variable removal up to Ansible 1.5, as this was the only thing blocking the timely removal of that “feature”.

This marks the final end of our push to clean up the few remaining experimental/gross things from the early days of Ansible, and we’ve finally found our feet in the way we want things to be in pruning away most of the spooky stuff. This means the alternative {{ foo }} has been available and encouraged as the proper way to do things for about 8 months when we finally remove it in December or January.

Once 1.5 development starts, removal of the legacy variable code will reduce the complexity in Ansible’s templating source by about 3/4 and help ensure we all write playbooks the same way.

I’ll continue to work on the syntax checker-reporter so it doesn’t identify any false positives.

Testing is all super welcome.

Michael,

I’m experiencing issues w/ the latest -devel and the lookup plugin. Before this commit the following playbook used to work:

This seems to be the same issue:

https://github.com/ansible/ansible/issues/4608

So let’s rejoice, as a result, we are moving the deprecation plan for legacy variable removal up to Ansible 1.5, as this was the only thing blocking the timely removal of that “feature”.

BTW I came across one example of $foo usage in the website:

http://www.ansibleworks.com/docs/faq.html#how-do-i-copy-files-recursively-onto-a-target-host

   local_action: command rsync -a /path/to/files $inventory_hostname:/path/to/target/

(There’s also a mention of “$groups” in the previous question, but not actually used in that format)