Set jinja2_native at play level?

Hi

I'm in a situation where I have a role that relies on
ANSIBLE_JINJA2_NATIVE=True.
However, setting this option in my ansible.cfg is causing breakage in
many older playbooks.

Is there a way to configure this behavior more granularly, for
instance at role/play level?

Thx

not currently, but you can do so via environment variable in the
command line when executing new/old playbooks

ANSIBLE_JINJA2_NATIVE=1 ansible-playbook newplay.yml

Thanks, this works.
However, the playbook also "works" without setting this, in the sense
that various template related task will yield unexpected results,
messing things up down the line.

My approach was then to start my playbook with something like this:

    - name: Ensure variable types with Jinja2
      assert:
        that: lookup('env', 'ANSIBLE_JINJA2_NATIVE')

This at least avoids running the playbook without this environment var set.
But then it also doesn't work if you have the "regular" option
switched on ("jinja2_native = True" in ~/.ansible.cfg, for instance).

I accept that there is no way to set configuration options at play
level, but is there be a way to check for them?
Then I can at least make an informed decision about continuing or not.

The root cause seems to be a lot of historic cruft that expects
everything returned form jinja2 to be strings, which is not easy to
fix...

thx!

use this lookup instead
https://docs.ansible.com/ansible/latest/plugins/lookup/config.html, it
will handle 'actual configuration value' instead of relying on the
specific source used.

exactly what i'm looking for, thx!