I have a situation where I'm writing a playbook for changing attributes of virtual machine, and the input I get comes from an automation that outputs the following, which is then passed in extra_vars:
{
"vmvars": {
"v_ads1as_operating_system": "Linux",
"v_mdjx2d_vm_name": "myvm123",
"v_srsj4d_mount_point": "tmp"
}
}
As you can see, the key in vmvars, the string v_<something> is not consistent and can be anything. The remaining string of the key for e.g. _operating_system remains the same.
I know the key should be unique. Well it is unique, sadly some of it is random.
Now in order to get the values I've tried the following, however none of them seem to work.
---
- hosts: localhost
tasks:
- name: Get os_type from input
set_fact:
os_type: "{{ vmvars[item] | json_query(['*operating_system']) }}"
loop: "{{ vmvars.keys() | list }}"
More queries that I've tried.
- set_fact:
os_type: "{{ vmvars[item] | json_query(vmvars['*operating_system']) }}"
- set_fact:
os_type: "{{ vmvars[item] | json_query([?contains(item,'operating_system')]) }}"