Home > Blockchain >  How do I return specific value from ansible debug
How do I return specific value from ansible debug

Time:04-05

I am using the below code to get information about a GCP instance.

- name: get info on an instance
  gcp_compute_instance_info:
    filters:
    - name = "{{ ansible_hostname }}"
    project: "{{ gcp_project }}"
    zone: "{{ gcp_zone }}"
    auth_kind: machineaccount
    service_account_email: [email protected]
  register: result

- name: show result
  debug:
   var: result.resources

I get this result:

ok: [sas-test-instance-01] => {
10:33:42            "result": {
10:33:42                "changed": false,
10:33:42                "failed": false,
10:33:42                "resources": [
10:33:42                    {
10:33:42                        "canIpForward": false,
10:33:42                        "confidentialInstanceConfig": {
10:33:42                            "enableConfidentialCompute": false
10:33:42                        },
10:33:42                        "cpuPlatform": "Intel Haswell",
10:33:42                        "creationTimestamp": "2022-02-09T15:08:40.408-08:00",
10:33:42                        "deletionProtection": false,
10:33:42                        "description": "",
10:33:42                        "disks": [
10:33:42                            {
10:33:42                                "autoDelete": true,
10:33:42                                "boot": true,
10:33:42                                "deviceName": "sas-test-instance-01",
10:33:42                                "diskSizeGb": "40",
10:33:42                                "index": 0,
10:33:42                                "interface": "SCSI",
10:33:42                                "kind": "compute#attachedDisk",
10:33:42                                "licenses": [
10:33:42                                    "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses/centos-7"
10:33:42                                ],
10:33:42                                "mode": "READ_WRITE",
10:33:42                                "source": "https://www.googleapis.com/compute/v1/projects/freshbooks-staging/zones/us-east1-b/disks/sas-test-instance-01",

What I want is to pull the disk source information into a var but I can't seem to target that specific information.

for example:

- name: show result
  debug:
   var: result.resources.disk

doesn't work

any tips?

CodePudding user response:

- name: show result
  debug:
   msg: {{ result.resources[0].disks[0].source }}
  • Related