如何从 ansible 调试返回特定值

发布于 2025-01-16 04:07:58 字数 2405 浏览 0 评论 0原文

我使用以下代码来获取有关 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: [email protected]
  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

没有

任何提示吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦断已成空 2025-01-23 04:07:58
- name: show result
  debug:
   msg: {{ result.resources[0].disks[0].source }}
- name: show result
  debug:
   msg: {{ result.resources[0].disks[0].source }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文