0

我想na_ontap_command使用 ansible-playbooks 打印模块生成的存储文件管理器版本输出。

我试图在一个变量中注册结果并使用调试消息打印它,但我收到了错误。

`---
- 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
`

我的剧本应该返回存储文件管理器的版本NetApp Release 9.1P8

这是我得到的调试:

>TASK [debug] ***********************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "command_result.stdout_lines": "VARIABLE IS NOT DEFINED!"
}
4

2 回答 2

0

尝试这个:

register: output
- name: print CLI Output
  debug: 
    msg: 
     - "output": "{{output.msg.split('\n')}}
于 2019-05-09T06:16:31.543 回答
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

执行后的结果:

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>"
    }
}
于 2019-04-01T07:43:47.813 回答