simple problem but can't figure it out

15 views
Skip to first unread message

Dick Visser

unread,
Feb 1, 2023, 8:56:38 AM2/1/23
to ansible...@googlegroups.com
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.....

Rowe, Walter P. (Fed)

unread,
Feb 1, 2023, 8:58:02 AM2/1/23
to ansible...@googlegroups.com
Look at the ansible filters documentation. They provide examples.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAF8BbLbtQHJu8zzJLOdv27uC%2BtU_DNnxOOmMbRCGqdgNRaGSLA%40mail.gmail.com.

Dick Visser

unread,
Feb 1, 2023, 9:07:01 AM2/1/23
to ansible...@googlegroups.com


On Wed, 1 Feb 2023 at 14:57, 'Rowe, Walter P. (Fed)' via Ansible Project <ansible...@googlegroups.com> wrote:
Look at the ansible filters documentation. They provide examples.

ehm, yes, I did get that...

It's as simple as:

"{{ my_list | json_query('[].{somekey:@}') }}"




Reply all
Reply to author
Forward
0 new messages