1

我有一个 Ansible 脚本,我只是使用 junos_command 模块从 Juniper 交换机获取用户列表,下面是我的代码片段。每当我尝试运行它时,我都会不断收到 RuntimeWarning。此外,我已经能够使用下面的代码本身成功地运行诸如“显示版本”之类的命令。请帮忙

脚本:

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

错误:

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}
4

1 回答 1

2

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

对于此类配置数据,您应该使用带有 junos_command 的 rpc 选项(get-configuration)。

junos_command:
rpcs:
  - "get_configuration

您也可以使用 junos_get_config。

http://junos-ansible-modules.readthedocs.io/en/latest/junos_get_config.html

或 junos_rpc

https://github.com/Juniper/ansible-junos-stdlib/blob/master/library/junos_rpc

前任:

- 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

或者

  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 : 好的=1 更改=1 无法访问=0 失败=0

于 2016-08-31T10:13:12.670 回答