You can only use Jinja2 expressions.
Thank you Michael for this confirmation.
Why? We don't want playbooks to become arbitrary Python hackjobs.
Ansible is not a Python tool -- something that is only appealing to Python
developers. Rather, it's a tool that is written in Python.
Ansible is not a Python tool, but it's neither a Jinja tool
I would argue that very few developers outside the Python ecosystem know
Jinja, which makes playbooks with Jinja expressions even more "Pythonesque"
than playbooks with Python expressions.
It definitely makes sense to restrict Python to Ansible internals as much
as possible, and not let it "bleed" into the public API. (It was the reason
behind the pull request I made a few months ago to remove Python specific
quoting from Ansible playbooks.)
Yet, playbooks still need an expression language, and whatever syntax is
used, Jinja or Python's one, they are both a "foreign" syntax into Ansible
playbooks. I'm not sure to understand why a Ruby or a Perl developer would
be more comfortable with Jinja's syntax than Python's one:
- Jinja's syntax is less documented than Python's syntax which has
excellent documentation.
- Jinja's syntax is perfect for a templating engine, but I doubt it's a
good fit for an orchestration tool. Python's syntax is more general and
closer to what people use in mainstream languages (Java, C, JavaScript,
Ruby, Perl, PHP, etc.).
Jinja2 templating allows us direct access to all of our variables with
reasonable constrains without allowing you to do things like "os.system()"
in the middle of an operation.
I understand this argument in theory. But is it a problem in practice (i.e.
having someone abusing the playbook expressions and breaking Ansible
expected behavior)?