Ansible 解析 JSON 输出

Ansible parse JSON output

我正在尝试解析 Ansible 输出并打印一个值

- name: Creating a new instance
  os_server:
  state: present
  auth:
  auth_url: "{{ auth_url }}"
  username: "{{ username }}"
  password: "{{ password }}"
  project_name: "{{ project_name }}"
name: "{{ item.hostname }}"
image: "{{ item.image }}"
nics: "{{ nics }}"
with_items: "{{ servers }}"
register: "os"

输出:

"server": {
    "OS-DCF:diskConfig": "MANUAL", 
    "OS-EXT-AZ:availability_zone": "zoneA", 
    "OS-EXT-STS:power_state": 1, 
    "OS-EXT-STS:task_state": null, 
    "OS-EXT-STS:vm_state": "active", 
    "OS-SRV-USG:launched_at": "2018-04-01T18:53:16.000000", 
    "OS-SRV-USG:terminated_at": null, 
    "accessIPv4": "10.190.230.23", 
    "accessIPv6": "", 
    "addresses": {
        "provider_corenet_bif_757": [
            {
                "OS-EXT-IPS-MAC:mac_addr": "fa:1:3:3:5e:6a", 
                "OS-EXT-IPS:type": "fixed", 
                "addr": "10.19.23.23", 
                "version": 4
            }
        ], 
        "provider_nmnet_bif_912": [
            {
                "OS-EXT-IPS-MAC:mac_addr": "fa:1:3:39:b:57", 
                "OS-EXT-IPS:type": "fixed", 
                "addr": "10.25.13.64", 
                "version": 4
            }
        ]

      server.addresses.provider_nmnet_bif_912.addr

    },

我想解析地址“10.25.13.64”。

我试过 {{ item.server.addresses.provider_nmnet_bif_912.addr }} 和 {{os.server.addresses.provider_nmnet_bif_912.addr}} 都没有用。

需要帮助!!!

终于想通了:

"{{ item.server.addresses.provider_nmnet_bif_912[0].addr }}"