On 28. juli 2017 21:52, [email protected] wrote:
I am wondering if it possible to do this kind of form in a playbook. I know
how to do it in a template:
If I have some data of the form:
mydict:
- entry1:
data: xyzzy
filename: scroll.txt
- entry2:
data: boom
filename: sound.txt
things:
- entry1
- entry2
In a template, I can to do this:
{% for item in things %}
data = {{ mydict[item]['data'] }}
filename = {{ mydict[item]['filename'] }}
{% endfor %}
Are you sure this work?
This will fail in the same way as your task below.
What I want to do is in a role task is
- name test copy from variable
copy:
content: "{{ mydict[item]['data'] }}
dest: "{{ target_dir }}/{{ mydict[item]['filename'] }}'
with_items: things
I can't seem to find the right way to get this to work in a playbook. All
my attempts with dots and brackets have failed.
Can someone explain how to represent this in a playbook?
mydict is not a dict but a list.
So correct syntax is
{{ mydict[item][0]['data'] }} for the first and {{
mydict[item][1]['data'] }} for the second.
If you remove the dashes in front of entry1 and 2 you'll get a dict and
both of your examples will work.
--
Kai Stian Olstad
--
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/29c07bb8-ab9a-9d54-d83b-205168cd67ea%40olstad.com.
For more options, visit https://groups.google.com/d/optout.