Access all the sub-elements in a yaml map

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

i think what you need is with_dict: object and use it via item.key and item.value

Thanks. Works as expected.