无法从 na_ontap_command ansible 模块打印标准输出

Cannot print stdout from na_ontap_command ansible module

我正在尝试从 NetApp ONTAP9.8P6 上的 na_ontap_command ansible module 获取 stdout_lines 输出。

这给了我完整的输出:

 tasks:
  - name: Version CLI Command
    na_ontap_command:
      command: ['version']
      return_dict: yes
      <<: *login
    register: cluster_version

  - name: Print Output
    debug:
      msg: "{{ cluster_version }}"

输出:

    ok: [localhost] => {
    "msg": {
        "changed": true,
        "failed": false,
        "msg": {
            "invoked_command": "version",
            "result_value": 1,
            "status": "passed",
            "stdout": "NetApp Release 9.8P6: Tue Aug 03 16:21:11 UTC 2021\n",
            "stdout_lines": [
                "NetApp Release 9.8P6: Tue Aug 03 16:21:11 UTC 2021"
            ],
            "xml_dict": {
                "active_element": "",
                "cli-output": {
                    "attrs": {},
                    "data": "NetApp Release 9.8P6: Tue Aug 03 16:21:11 UTC 2021\n"
                },
                "cli-result-value": {
                    "attrs": {},
                    "data": "'1'"
                },
                "last_element": "results",
                "results": {
                    "attrs": {
                        "status": "passed",
                        "xmlns": "http://www.netapp.com/filer/admin"
                    },
                    "data": ""
                }
            }
        }
    }
}

我怎样才能打印出来,例如标准输出或 stdout_lines?

我找到了带有 msg 的示例:“{{ cluster_version.stdout }}”或 looping through results

msg:“{{ cluster_version.stdout }}”以以下错误消息结束:

"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout'\

我不知道如何在我的案例中使用循环,因为在我的剧本的输出中找不到结果关键项。

也许有人经历过这种情况并且可以提供想法或解决方案?谢谢!

注册的变量 cluster_version 中包含另一个字典,即 msg

所以要获得 stdoutstdout_lines,您需要参考 cluster_version['msg'],如下所示:

- debug:
    var: cluster_version['msg']['stdout']