我如何 return 来自 ansible 调试的特定值

How do I return specific value from ansible debug

我正在使用以下代码获取有关 GCP 实例的信息。

- 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: mysql-service-account@email.com
  register: result

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

我得到这个结果:

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",

我想要的是将磁盘源信息提取到一个 var 中,但我似乎无法针对该特定信息。

例如:

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

不起作用

有什么建议吗?

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