On 11.02.17 16:14 Dhaval Joshi wrote:
> 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 ?

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

-- 
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/fed4b177-320d-220d-d119-3244e128f908%40ojkastl.de.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to