It works. Thanks a lot Kai Stian Olstad.
On Sunday, 26 August 2018 16:38:04 UTC-4, Kai Stian Olstad wrote:
>
> On Sunday, 26 August 2018 21.13.42 CEST Saravanan Ponnusamy wrote:
> >
> > Variables declared as an array in an external file. Need to read these
> > variables recursively in the playbook during play for multiple records.
> > Request to suggest right looping to use in Ansible playbook.
> >
> > Currently able to get the item and not item.[variable].
> >
> >
> > Playbook:
> >
> > ---
> > - hosts: 127.0.0.1
> > gather_facts: no
> >
> > tasks:
> > - debug:
> > var: "{{ item }}"
> > with_lines: cat array.yaml
> >
> >
> > $ cat array.yaml
> >
> > - { name: user1, uid: 1001, env: dev, app: app1 }
> > - { name: user2, uid: 1002, env: cit, app: app2 }
>
> You need to put them in a dictionary, then you can do this.
>
> array.yml
> ---
> myvar:
> - { name: user1, uid: 1001, env: dev, app: app1 }
> - { name: user2, uid: 1002, env: cit, app: app2 }
>
>
> tasks:
> - include_vars: array.yml
>
> - debug: msg="{{ item.name }} {{ item.uid }} {{ item.env }} {{
> item.app }}"
> with_items: '{{ myvar }}'
>
>
> --
> 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/76f0616c-dbf2-4fdb-8d95-26aa4f31ad71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.