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...