From this YAML output I need to get the datacenter value in a variable.
changed: "false"
clusters:
ADC_CORE4:
hosts:
- name: "b125.abc.com"
folder: "/ADC_3C/host/ADC_CORE4"
enable_ha: "true"
ha_failover_level: "2"
resource_summary:
cpuCapacityMHz: "2183328"
cpuUsedMHz: "71374"
moid: "test"
datacenter: "ADC_AI"
But the key ADC_CORE4 is not stable and changes on every output I get when the cluster changes.
I like to get the datacenter value from this output and trying to use it in deployment of VM.
Assuming that your example YAML data is the content of a variable
myvariable, you can get thedatacentervalue like this:The
values()method returns a list of values; since there's only a single value, we just grab the first item in the list and then ask for thedatacenterattribute.For example: