D11
(D)
1
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
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