ansiblenetapp

Cannot print stdout from na_ontap_command ansible module


I'm trying to get stdout_lines output from na_ontap_command ansible module on NetApp ONTAP9.8P6.

This gives me the complete output:

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

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

Output:

    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": ""
                }
            }
        }
    }
}

How can I just print e.g. stdout or stdout_lines?

I found examples with msg: "{{ cluster_version.stdout }}" or looping through results.

msg: "{{ cluster_version.stdout }}" ends in following error msg:

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

And the looping I dont know how to use in my case as the results key-item cannot be found in the output of my playbook.

Maybe someone has experienced this and could help with an idea or solution? Thanks!


Solution

  • The registered variable cluster_version contains another dictionary within, i.e. msg.

    So to get the stdout or stdout_lines, you need to refer with cluster_version['msg'], like below:

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