simple problem but can't figure it out

Hi

I am looking for a way to transform a list of strings into a list of dicts, where the string is a certain key’s value - without using a loop. So from this:

my_list:

  • foo
  • bar
  • baz

to:

other_list:

  • somekey: foo
  • somekey: bar
  • somekey: baz

It looks too simple but I can’t see how to do this…

Look at the ansible filters documentation. They provide examples.

Walter

ehm, yes, I did get that…

It’s as simple as:

“{{ my_list | json_query(‘.{somekey:@}’) }}”