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
On Wednesday, 14 December 2016 13:26:28 UTC, vu001 wrote:
>
> 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*
> ---
> - name: Demo of with_nested
> hosts: host1
> vars:
> FS_LIST:
> member1:
> FS: "/tmp/f1/dev"
> config_files: ["config1.xml","config2.xml"]
> member2:
> FS: "/tmp/f2/dev"
> config_files: ["config1.xml"]
> tasks:
> - name: Printing message
> debug: msg=" {% for i in item.config_files %} Values are {{item.FS}}
> and {{i}}\n{% endfor %} "
> with_items:
> - "{{FS_LIST.values()}}"
>
> and it prints mi all permutation as I wish
> "msg": " Values are /tmp/f1/dev and config1.xml\n Values are
> /tmp/f1/dev and config2.xml\n "
> "msg": " Values are /tmp/f2/dev and config1.xml\n "
>
>
> So i tried to implement this logic to template:
> This template is just to check syntax:
> ---
> - name: Demo of with_nested
> hosts: host1
> vars:
> FS_LIST:
> member1:
> FS: "/tmp/f1/dev"
> config_files: ["config1.xml","config2.xml"]
> member2:
> FS: "/tmp/f2/dev"
> config_files: ["config1.xml"]
> tasks:
> - name: Printing message
> template: src=/tmp/config1.xml.j2 dest={{item.FS}}/config1.xml
> with_items:
> - "{{FS_LIST.values()}}"
>
> *BUT*
> When i tried to do this:
> ---
> - name: Demo of with_nested
> hosts: host1
> vars:
> FS_LIST:
> member1:
> FS: "/tmp/f1/dev"
> config_files: ["config1.xml","config2.xml"]
> member2:
> FS: "/tmp/f2/dev"
> config_files: ["config1.xml"]
> tasks:
> - name: Printing message
> * template: {% for i in item.config_files %} src={{i}}.j2
> dest={{item.FS}}/{{i}} {% endfor %}*
> with_items:
> - "{{FS_LIST.values()}}"
>
>
> I got error:
> The offending line appears to be:
>
> - name: Printing message
> template: {% for i in item.config_files %} src={{i}}.j2
> dest={{item.FS}}/{{i}} {% endfor %}
> ^ here
> We could be wrong, but this one looks like it might be an issue with
> missing quotes. Always quote template expression brackets when they
> start a value. For instance:
>
> with_items:
> - {{ foo }}
>
> Should be written as:
>
> with_items:
> - "{{ foo }}"
>
>
> Any idea...thanks a lot...
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/4f19ee01-1cd8-487a-b62a-9ec864697f05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.