Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to select nested values?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 {...}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading