Access all the sub-elements in a yaml map

96 views
Skip to first unread message

Naween Ghimire

unread,
Jun 5, 2015, 2:02:17 AM6/5/15
to ansible...@googlegroups.com
Hi I have been trying to access all the sub-elements available in a map but i am unable to do so:

Here's my usecase:

A yaml map is defined as follows:

object:
    element1: "value1"
    element2: "value2"
    element3: "value3"
    ...
    ...
    ...
    elementn: "valuen"

In a task i need to access all the values (value1,value2,value3,...,valuen)

I tried the following:

- name: pass values to script
      debug: "msg={{ item }}"
      with_items:
        - "{{ object }}"

But this doesn't seem to work.

Whereas the following works,

- name: pass values to script
      debug: "msg={{ item }}"
      with_items:
        - "{{ object.element1 }}"
        - "{{ object.element2 }}"

But this is not scalable, and i have a usecase where the number of elements might vary. Is there a way to get this done in ansible ?


Regards,
Naween

benno joy

unread,
Jun 5, 2015, 2:11:02 AM6/5/15
to ansible...@googlegroups.com
i think what you need is with_dict: object and use it via item.key and item.value


--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/da9e4739-eefa-4975-adc3-65ad0b6a3610%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Naween Ghimire

unread,
Jun 5, 2015, 2:42:26 AM6/5/15
to ansible...@googlegroups.com
Thanks. Works as expected.
Reply all
Reply to author
Forward
0 new messages