Using keys from the json src doc in a multiselect hash with Jmespath
First of all im not sure you should go through all that troble.If you are uncertain witch keys you are goin to get, than you probebly would iterate through your entire json, and so, you know your item
key.
Nevertheless, if you just want to export a new json, I was unable to find a way to use native JMESPath to do so. instead I used an ansible with_dict
loop as follow:
- name: Create new nic_dict json set_fact: nic_dict: "{{ {item.key: item.value.mac} | combine(nic_dict | default({})) }}" with_dict: "{{ nics }}"
Now you can use the nic_dict
that looks like this:
"nic_dict": { "vlan_external": "aa:aa:aa:aa:aa:bb", "vlan_internal": "aa:aa:aa:aa:aa:aa"}