Ansible 打印来自 vmware_host_vmhba_facts 的特定字段

Ansible print specific fields from vmware_host_vmhba_facts

我正在使用 vmware_host_vmhba_facts 模块,我的目标是为任何 esx 提取 hbas 的状态。

我附上一个简短的输出:

PLAY [Check HBA status] **********************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Gather facts about vmhbas of all ESXi Host in the given Cluster] ***********************************************************************************************************************************************************************
ok: [localhost -> localhost]

TASK [debug] *********************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "cluster_host_vmhbas": {
        "changed": false,
        "failed": false,
        "hosts_vmhbas_facts": {
            "ita-esx01.net": {
                "vmhba_details": [
                    {
                        "adapter": "Intel Corporation Lewisburg SATA AHCI Controller",
                        "bus": 0,
                        "device": "vmhba38",
                        "driver": "ahci",
                        "location": "0000:00:11.5",
                        "model": "Lewisburg SATA AHCI Controller",
                        "status": "unknown",
                        "type": "BlockHba"
                    },
                    {
                        "adapter": "QLogic Corp 2600 Series 16Gb Fibre Channel to PCI Express HBA",
                        "bus": 95,
                        "device": "vmhba3",
                        "driver": "qlnativefc",
                        "location": "0000:5f:00.0",
                        "model": "2600 Series 16Gb Fibre Channel to PCI Express HBA",
                        "node_wwn": "23:06:11:22:94:35:05:46:63",
                        "port_type": "unknown",
                        "port_wwn": "23:06:39:37:69:32:72:57:29",
                        "speed": 16,
                        "status": "online",
                        "type": "Fibre Channel"
                    }
                ]
            },
            "ita-esx02.net": {
                "vmhba_details": [
                    {
                        "adapter": "Intel Corporation Lewisburg SATA AHCI Controller",
                        "bus": 0,
                        "device": "vmhba38",
                        "driver": "ahci",
                        "location": "0000:00:11.5",
                        "model": "Lewisburg SATA AHCI Controller",
                        "status": "unknown",
                        "type": "BlockHba"
                    },
                    {
                        "adapter": "QLogic Corp 2600 Series 16Gb Fibre Channel to PCI Express HBA",
                        "bus": 95,
                        "device": "vmhba4",
                        "driver": "qlnativefc",
                        "location": "0000:5f:00.1",
                        "model": "2600 Series 16Gb Fibre Channel to PCI Express HBA",
                        "node_wwn": "23:06:11:22:94:35:05:46:64",
                        "port_type": "unknown",
                        "port_wwn": "23:06:39:37:69:32:72:57:30",
                        "speed": 16,
                        "status": "online",
                        "type": "Fibre Channel"
                    },

在这个输出之后,我想要一个类似的输出:

ita-esx01.net:
vmhba38 status unknown
vmhba3  status online

ita-esx02.net:
vmhba38 status unknown
vmhba4 status online

你有什么提示吗? 谢谢

比如select数据先

- set_fact:
    net_status: "{{ net_status|
                    default({})|
                    combine({item.key: item.value.vmhba_details|
                                       json_query('[].{key: device,
                                                       value: status}')})
                    }}"
  loop: "{{ cluster_host_vmhbas.hosts_vmhbas_facts|dict2items }}"

然后打印出来

- debug:
    msg: "{{ msg.split('\n') }}"
  vars:
    msg: |
      {{ item.key }}:
      {% for dev in item.value %}
      {{ dev.key }} status {{ dev.value }}
      {% endfor %}
  loop: "{{ net_status|dict2items }}"

删节输出为

"msg": [
    "ita-esx02.net:", 
    "vmhba38 status unknown", 
    "vmhba4 status online", 
    ""
]

"msg": [
    "ita-esx01.net:", 
    "vmhba38 status unknown", 
    "vmhba3 status online", 
    ""
]