首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >junos_command模块不返回输出

junos_command模块不返回输出
EN

Stack Overflow用户
提问于 2016-08-30 22:26:17
回答 1查看 1.7K关注 0票数 1

我有一个Ansible脚本,我只是使用junos_command模块从Juniper获取用户列表,下面是我的代码片段。每当我尝试运行这个程序时,我都会一直得到RuntimeWarning。此外,我已经成功地使用下面的代码运行了类似于“显示版本”之类的命令。请帮帮忙

脚本:

代码语言:javascript
复制
name: / GET USERS / Get list of all the current users on switch

action: junos_command

args: { commands: 'show configuration system login',
          provider: "{{ netconf }}" }

register: curr_users_on_switch

错误:

代码语言:javascript
复制
TASK [/ GET USERS / Get list of all the current users on switch] ***************
fatal: [rlab-er1]: FAILED! => {"changed": false, "failed": true, "module_stderr": "/home/mbhadoria/.local/lib/python2.7/site-packages/jnpr/junos/device.py:429: RuntimeWarning: CLI command is for debug use only!
\n  warnings.warn(\"CLI command is for debug use only!\", RuntimeWarning)\nTraceback (most recent call last):
\n  File \"/tmp/ansible_lVOmPp/ansible_module_junos_command.py\", line 261, in <module>
\n    main()
\n  File \"/tmp/ansible_lVOmPp/ansible_module_junos_command.py\", line 233, in main
\n    xmlout.append(xml_to_string(response[index]))
\n  File \"/tmp/ansible_lVOmPp/ansible_modlib.zip/ansible/module_utils/junos.py\", line 79, in xml_to_string\n  File \"src/lxml/lxml.etree.pyx\", line 3350, in lxml.etree.tostring (src/lxml/lxml.etree.c:84534)\nTypeError: Type 'str' cannot be serialized.
\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}
EN

回答 1

Stack Overflow用户

发布于 2016-08-31 10:13:12

junos_command只支持junos操作命令。您要运行的是配置命令。因此,您可以看到“显示版本”,这是操作命令工作,而不是“显示配置系统登录”。

对于这样的配置数据,您可以在junos_command中使用rpc选项(get- configuration )。

代码语言:javascript
复制
junos_command:
rpcs:
  - "get_configuration

您也可以使用junos_get_config。

config.html

或junos_rpc

rpc

例:

代码语言:javascript
复制
- name: Junos OS version
  hosts: all
  connection: local
  gather_facts: no
  tasks:
    - name: Get rpc run
      junos_rpc:
        host={{ inventory_hostname }}
        user=xxxx
        passwd=xxx
        rpc=get-config
        dest=get_config.conf
        filter_xml="<configuration><system><login/></system></configuration>"
      register: junos

代码语言:javascript
复制
  tasks:
   - name: Get rpc run
     junos_get_config:
       host: "{{ inventory_hostname }}"
       user: xxxx
       passwd: xxxx
       logfile: get_config.log
       dest: "{{ inventory_hostname }}.xml"
       format: xml
       filter: "system/login"

任务获取rpc运行*************************************************************

.

播放重述*********************************************************************

xxxk : ok=1 changed=1 unreachable=0 failed=0

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39238026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档