# Set jinja2\_native at play level?

**URL:** <https://forum.ansible.com/t/set-jinja2-native-at-play-level/30000>\
**Category:** Ansible Project\
**Created:** [March 27, 2019, 6:43pm UTC](https://forum.ansible.com/t/set-jinja2-native-at-play-level/30000 "2019-03-27T18:43:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 27, 2019, 6:43pm UTC](https://forum.ansible.com/t/set-jinja2-native-at-play-level/30000/1 "2019-03-27T18:43:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 9, 2019, 1:53pm UTC](https://forum.ansible.com/t/set-jinja2-native-at-play-level/30000/2 "2019-04-09T13:53:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 9, 2019, 3:05pm UTC](https://forum.ansible.com/t/set-jinja2-native-at-play-level/30000/3 "2019-04-09T15:05:09Z")

</div>

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:

&nbsp;&nbsp;&nbsp;&nbsp;- name: Ensure variable types with Jinja2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 9, 2019, 6:08pm UTC](https://forum.ansible.com/t/set-jinja2-native-at-play-level/30000/4 "2019-04-09T18:08:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 9, 2019, 9:45pm UTC](https://forum.ansible.com/t/set-jinja2-native-at-play-level/30000/5 "2019-04-09T21:45:53Z")

</div>

exactly what i'm looking for, thx!
