从 Ansible 寄存器输出值中获取部分寄存器值

问题描述 投票:0回答:1

尝试从 ansible 寄存器输出中获取特定属性值。下面附上输出值。请在这里帮忙获取该值。对于我来说,它是相当复杂的嵌套,因为我对 ansible 完全陌生。

enter image description here

ansible registry
1个回答
0
投票

A 最小可重现示例

---
- hosts: localhost
  become: false
  gather_facts: false

  vars:

    results: [
      {
        "ansible loop var": "item",
        "changed": false,
        "exists": true,
        "failed": false,
        "item": [
          "TMS",
          "InterThread"
        ],
        "properties": {
          "Audit": {
            "raw value": 1,
            "type": "REG_DWORD",
            "value": 1
          },
          "Authenticator": {
            "raw_value": "111",
            "type": "REG_SZ",
            "value": "111"
          },
        }
      }
    ]

  tasks:

  - name: Audit
    debug:
      msg: 'value: "{{ (results | first).properties.Audit.value }}" has type: "{{ (results | first).properties.Audit.type }}"'

  - name: Auth
    debug:
      msg: 'value: "{{ (results | first).properties.Authenticator.value }}" has type: "{{ (results | first).properties.Authenticator.type }}"'

将产生

的输出
TASK [Audit] ****************************
ok: [localhost] =>
  msg: 'value: "1" has type: "REG_DWORD"'

TASK [Auth] *****************************
ok: [localhost] =>
  msg: 'value: "111" has type: "REG_SZ"'
© www.soinside.com 2019 - 2024. All rights reserved.