There is a list:
mylist: ['a_value', 'something_else']
There is a dict:
my_dict:
a_value:
something: true
bar:
foo: false
something_else:
placeholder: true
There is an Ansible task to set a fact for a new dict.
- name: "Create a new dict, when name(s) in the list match the key in the dict"
set_fact:
new_dict: "{{ new_dict | default({}) | combine({item.key: item.value}) }}"
loop:
- "{{ my_dict | dict2items }}"
- "{{ my_list }}"
when: my_list??? item
Q: How would I configure Ansible to create a new dict, when the name(s) match the key in the dict?
In this example, desired output:
new_dict:
a_value:
something: true
something_else:
placeholder: true