The following is the output (return values) of an Ansible module (Oracle Cloud Networking Module). I want to get nested values. I tried with:
var=result_pub_ips_reserved.public_ips.assigned_entity_id
but this does not work. Am I missing something?
Code:
ok: [localhost] => {
"result_pub_ips_reserved": {
"changed": false,
"failed": false,
"public_ips": [
{
"assigned_entity_id": "ocid1.privateip.oc1.eu-frankfurt-1.abtheljtfhzqfze7tvfgbesdkytmf6xaiegwjfjcpw73gamozymt6jh2xrya",
"assigned_entity_type": "PRIVATE_IP",
"availability_domain": null,
"compartment_id": "ocid1.compartment.oc1..aaaaaaaadnurmgbsrwgao42kohyg6t7qil35c2hkjrhicchnltra45fwavma",
"defined_tags": {},
"display_name": "anakin-pub-ip",
"freeform_tags": {},
"id": "ocid1.publicip.oc1.eu-frankfurt-1.amaaaaaafzy3a4ya2af5l26fnrjvq2tr4mmipqdqoei5o7o72ir5h5olds4a",
"ip_address": "144.24.171.161",
"lifecycle_state": "ASSIGNED",
"lifetime": "RESERVED",
"private_ip_id": "ocid1.privateip.oc1.eu-frankfurt-1.abtheljtfhzqfze7tvfgbesdkytmf6xaiegwjfjcpw73gamozymt6jh2xrya",
"public_ip_pool_id": null,
"scope": "REGION",
"time_created": "2022-02-22T12:34:35.878000+00:00"
}
]
}
}
>Solution :
"public_ips" is an array with a single element: a hash. You need to access the first element of that array, result_pub_ips_reserved.public_ips.0.assigned_entity_id, or remove the [...] around {...}