Groups
Groups
Sign in
Groups
Groups
Ansible Project
Conversations
About
Send feedback
Help
How to iterate over hash of arrays
14 views
Skip to first unread message
Dhaval Joshi
unread,
Feb 13, 2017, 9:07:12 AM
2/13/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ansible Project
Hello,
I have below strucure.
vars:
locations:
- parent_location: A
child_location:
- a1
- a2
- a3
- parent_location: B
child_location:
- b1
- b2
- b3
- parent_location: C
child_location:
- c1
- c2
- c3
now i have task something like below
command:
some-command '{{ A }}' create
command:
some-command '{{ a1 }}' --parent '{{ A }}'
command:
some-command '{{ b1 }}' --parent '{{ B }}'
and so-on, what's best way to achieve it ?
Thanks,
DJ
Johannes Kastl
unread,
Feb 13, 2017, 9:24:24 AM
2/13/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible...@googlegroups.com
Read the docs? ;-)
http://docs.ansible.com/playbooks_loops.html
https://docs.ansible.com/ansible/playbooks_loops.html#looping-over-hashes
https://docs.ansible.com/ansible/playbooks_loops.html#nested-loops
Something along the lines of:
command: some-command "{{ item.parent_location }}" create
with_dict: "{{ locations }}"
I guess for the child_locations you might need to adapt with_nested
somehow.
Johannes
signature.asc
Reply all
Reply to author
Forward
0 new messages