# Strange thing with Jinja2 expressions evaluation

**URL:** <https://forum.ansible.com/t/strange-thing-with-jinja2-expressions-evaluation/16196>\
**Category:** Ansible Project\
**Created:** [September 12, 2014, 2:07pm UTC](https://forum.ansible.com/t/strange-thing-with-jinja2-expressions-evaluation/16196 "2014-09-12T14:07:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrei\_Pashkin](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Andrei\_Pashkin](https://forum.ansible.com/u/Andrei_Pashkin)\
**Post date:** [September 12, 2014, 2:07pm UTC](https://forum.ansible.com/t/strange-thing-with-jinja2-expressions-evaluation/16196/1 "2014-09-12T14:07:44Z")

</div>

With this playbook:

> `- name: test playbook`  
> `� hosts: 127.0.0.1`  
> `� connection: local`  
> `� gather_facts: no`  
> `� tasks:`  
> `��� - debug: msg="{{ 'ansible'|replace('a', 'b') }}"`

Output will be:

> `"bnsible"`

But with this:

`- name: test playbook`  
`� hosts: 127.0.0.1`  
`� connection: local`  
`� gather_facts: no`  
`� tasks:`  
`��� - debug: msg="{{ 'ansible'|regex_replace('a', 'b') }}"`

Output will be:

> `"{{'ansible'|regex_replace('a', 'b')}}"`

Why in the last example expression is not evaluated?

ps  
I use Ansible 1.5.4

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [September 12, 2014, 2:12pm UTC](https://forum.ansible.com/t/strange-thing-with-jinja2-expressions-evaluation/16196/2 "2014-09-12T14:12:56Z")

</div>

That's a pretty old version of ansible. I suspect that the  
regex\_replace filter didn't exist then. You should definitely upgrade  
since it works on 1.7.1.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 12, 2014, 3:37pm UTC](https://forum.ansible.com/t/strange-thing-with-jinja2-expressions-evaluation/16196/3 "2014-09-12T15:37:27Z")

</div>

Yep yep.

(You’re also missing some security upgrades, so I would strongly recommend using 1.7.1 even if you don’t need this)

We try to note in the docs every time there’s a feature added in a specific version, but I see we didn’t do that for regex\_replace, so I’ll add the note about it.

Thanks very much for the report!

---

<div class="post-metadata">

**Author:** ![Andrei\_Pashkin](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Andrei\_Pashkin](https://forum.ansible.com/u/Andrei_Pashkin)\
**Post date:** [September 13, 2014, 10:35am UTC](https://forum.ansible.com/t/strange-thing-with-jinja2-expressions-evaluation/16196/4 "2014-09-13T10:35:33Z")

</div>

Yes indeed, I forgot to add Ansible PPA. Thanks!
