无法打印输出

时间:2019-04-01 06:47:08

标签: ansible netapp

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

我试图将结果注册到变量中,并使用调试消息将其打印出来,但出现错误。

`---
- 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!"
}

2 个答案:

答案 0 :(得分: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>"
    }
}

答案 1 :(得分:0)

尝试一下:

register: output
- name: print CLI Output
  debug: 
    msg: 
     - "output": "{{output.msg.split('\n')}}