# jinja2 for setting module parameters

**URL:** <https://forum.ansible.com/t/jinja2-for-setting-module-parameters/16051>\
**Category:** Ansible Project\
**Created:** [August 27, 2014, 4:01pm UTC](https://forum.ansible.com/t/jinja2-for-setting-module-parameters/16051 "2014-08-27T16:01:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xu\_Chen](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@Xu\_Chen](https://forum.ansible.com/u/Xu_Chen)\
**Post date:** [August 27, 2014, 4:01pm UTC](https://forum.ansible.com/t/jinja2-for-setting-module-parameters/16051/1 "2014-08-27T16:01:30Z")

</div>

I have difficulty using jinja2 combined with cron module in the following way:

- cron: name=test job=“abc {{ data | filter\_x(‘a’) | filter\_y(‘b’) }} edf”

I tried various combinations, but either the jinja2 template isn’t expanded, or I am seeing errors parsing.

Any ideas how to make something like this work? Thanks.

---

<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:** [August 27, 2014, 7:03pm UTC](https://forum.ansible.com/t/jinja2-for-setting-module-parameters/16051/2 "2014-08-27T19:03:22Z")

</div>

I assume filter\_x and filter\_y are plugins you wrote?

---

<div class="post-metadata">

**Author:** ![Xu\_Chen](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@Xu\_Chen](https://forum.ansible.com/u/Xu_Chen)\
**Post date:** [August 27, 2014, 7:44pm UTC](https://forum.ansible.com/t/jinja2-for-setting-module-parameters/16051/3 "2014-08-27T19:44:37Z")

</div>

Yes, I wrote some additional plugins and put them in ansible/lib/runner/filter\_plugins/core.py

Thanks.

---

<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:** [August 27, 2014, 8:11pm UTC](https://forum.ansible.com/t/jinja2-for-setting-module-parameters/16051/4 "2014-08-27T20:11:14Z")

</div>

Hard to say what you error is without seeing the plugin.

Perhaps you could paste it?

---

<div class="post-metadata">

**Author:** ![Xu\_Chen](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@Xu\_Chen](https://forum.ansible.com/u/Xu_Chen)\
**Post date:** [August 30, 2014, 4:23am UTC](https://forum.ansible.com/t/jinja2-for-setting-module-parameters/16051/5 "2014-08-30T04:23:39Z")

</div>

Ah, thanks for the hint…

I wrote a new filter function but didn’t register it in the end. Is there a way to make such errors more obvious? Like fail the execution and tell me jinja2 template expansion failed - currently the unexpanded template is directly used as the output…

Thanks.  
-Simon

---

<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 2, 2014, 11:02pm UTC](https://forum.ansible.com/t/jinja2-for-setting-module-parameters/16051/6 "2014-09-02T23:02:51Z")

</div>

Using a filter that doesn’t exist should generate an error, that I would definitely like a bug report on if you are not seeing that behavior in 1.7.X.

Thanks!
