# jinja in task (template)

**URL:** <https://forum.ansible.com/t/jinja-in-task-template/23255>\
**Category:** Ansible Project\
**Created:** [December 14, 2016, 1:26pm UTC](https://forum.ansible.com/t/jinja-in-task-template/23255 "2016-12-14T13:26:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![belajzus](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@belajzus](https://forum.ansible.com/u/belajzus)\
**Post date:** [December 14, 2016, 1:26pm UTC](https://forum.ansible.com/t/jinja-in-task-template/23255/1 "2016-12-14T13:26:28Z")

</div>

Hi to all,  
I have problem with evaluating jinja2 code in task (template)

**This is playbook for test, just to see If I get what I want**

---

<div class="post-metadata">

**Author:** ![Greg\_Langford](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@Greg\_Langford](https://forum.ansible.com/u/Greg_Langford)\
**Post date:** [December 15, 2016, 11:23am UTC](https://forum.ansible.com/t/jinja-in-task-template/23255/2 "2016-12-15T11:23:24Z")

</div>

Where you are defining the template task you should put double quotes round the jina code

e.g “{% for i in item.config\_files %} src={{i}}.j2 dest={{item.FS}}/{{i}} {% endfor %}” otherwise the jinja syntax will not be evaluated.

I have however never used a for loop in this fashion so no idea if that will work, I would be interested to hear if it does.

Kind Regards

---

<div class="post-metadata">

**Author:** ![belajzus](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@belajzus](https://forum.ansible.com/u/belajzus)\
**Post date:** [December 15, 2016, 12:24pm UTC](https://forum.ansible.com/t/jinja-in-task-template/23255/3 "2016-12-15T12:24:59Z")

</div>

I tried that also…but got error:

fatal: [host1]: FAILED! =\> {“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘i’ is undefined\n\nThe error appears to have been in ‘/etc/ansible/template\_jinja\_eval2.yml’: line 11, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Printing message\n ^ here\n”}

Dana četvrtak, 15. prosinca 2016. u 12:23:24 UTC+1, korisnik Greg Langford napisao je:
