So I think a lot about how to keep ansible as simple as it can
possibly be. The one place I think we can do better, but it's hard to
sometimes, is in how we handle variables and conditional operations.
I want to keep making this better.
For me at least, I think is is frequently somewhat confusing that we
have a simplified variable syntax in playbooks (also templates) but
that templates mainly use Jinja2 in examples.
I personally find the simplified template syntax very useful for
things like ${foo} or $foo but hard for complex things.
We will not be allowing Jinja2 operations of complexity in playbooks,
and running Jinja2 as often as we run our templating engine would be a
little sluggish anyway (we allow some lazy evaluation).
However, given all of this, I'm wondering.
What if {{ foo }} in playbooks just *worked* like jinja2, and you
/could/ put python statements in there?
We would obviously need to limit what you could do to data structures
an regular expressions only, but if one could say
{{ hostvars['asdf.example.com']['ansible_some_fact'] }}
while that is less beautiful, it would elimiate a large class of
variable concerns.
And this could also be allowed in conditionals, perhaps also
eliminating a class of conditional concerns, where the statement could
evaluate down to True or False
when: {{ (x > 52) }}
when: {{ y }}
when: {{ z in some_list }}
I think this may take a bit of a trick to implement well, though it
may also be possible to engage Jinja2 without the looping/other
constructs and tune to where performance is reasonable.
What do people think?
If this were the case we obviously leave $x and such in for backwards
compatibility (we must) but would probably move in 1.2 to keeping all
of your examples using the new way, and snapshotting the docs by
version.