0

I want to print storage filer version output generated by the na_ontap_command module using ansible-playbooks.

I tried to register the result in a variable and print it using a debug message, but I am getting error.

`---
- hosts: localhost
  name: run ontap cli command
  gather_facts: no
  connection: local
  vars_files:
  - var_file.yml
  tasks:
  - name: run ontap cli command
    na_ontap_command:
      command: ['version']
      https: true
      validate_certs: false
      hostname: "{{ hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"
    register: command_result
  - debug:
      var: command_result.stdout_lines
`

My playbook should return the version of the storage filer NetApp Release 9.1P8

This is the debug I am getting:

>TASK [debug] ***********************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "command_result.stdout_lines": "VARIABLE IS NOT DEFINED!"
}
Debugger
  • 494
  • 5
  • 18
  • and what is the error? – Sourav Ghosh Apr 01 '19 at 06:49
  • `fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (na_ontap_command) module: register Supported parameters include: command, hostname, http_port, https, ontapi, password, username, validate_certs")` –  Apr 01 '19 at 06:50
  • Did you check this? [reigster is not working with ansible git task](https://stackoverflow.com/q/44323190/2173917) – Sourav Ghosh Apr 01 '19 at 06:56
  • @SouravGhosh yeah it removed my error but still I am not getting the desired output, what is changed is `ok: [localhost] => { "command_result.stdout_lines": "VARIABLE IS NOT DEFINED!" } ` –  Apr 01 '19 at 07:02
  • Register was not well indented on the first version of your message – bast Apr 01 '19 at 07:16
  • if you print command_result what do you have ? – bast Apr 01 '19 at 07:17
  • @bast yes i corrected that –  Apr 01 '19 at 07:41
  • @bast i figured it out and posted it below. –  Apr 01 '19 at 07:45
  • @RavindraSinghRawat No problem, VTC as dupe. – Sourav Ghosh Apr 01 '19 at 07:47
  • 1
    Possible duplicate of [reigster is not working with ansible git task](https://stackoverflow.com/questions/44323190/reigster-is-not-working-with-ansible-git-task) – Sourav Ghosh Apr 01 '19 at 07:47
  • `stdout_lines` is usally available in the result with `command` or `shell` module. It does not exist in your case. – Zeitounator Apr 01 '19 at 09:09
  • @Zeitounator yeah i figured it out once i explored some of the blogs –  Apr 01 '19 at 09:48

2 Answers2

0
---
- hosts: localhost
  name: run ontap cli command
  gather_facts: no
  connection: local
  vars_files:
  - var_file.yml
  tasks:
  - name: run ontap cli command
    na_ontap_command:
      command: ['version']
      https: true
      validate_certs: false
      hostname: "{{ hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"
    register: command_result
  - debug:
      var: command_result

Result after executing:

TASK [debug] ***********************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "command_result": {
        "changed": true,
        "failed": false,
        "msg": "<results xmlns=\"http://www.netapp.com/filer/user\" status=\"passed\"><cli-output>NetApp Release 9.1P8: Wed Aug 30 13:33:41 UTC 2017\n\n</cli-output><cli-result-value>1</cli-result-value></results>"
    }
}
0

Try this:

register: output
- name: print CLI Output
  debug: 
    msg: 
     - "output": "{{output.msg.split('\n')}}
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Lei
  • 1