Ansible junos_命令模块未返回输出

Ansible junos_命令模块未返回输出,ansible,ansible-playbook,juniper-network-connect,junos-automation,Ansible,Ansible Playbook,Juniper Network Connect,Junos Automation,我有一个Ansible脚本,我只是使用junos_命令模块从Juniper switch获取用户列表,下面是我的代码片段。每当我尝试运行此程序时,都会收到RuntimeWarning。此外,我已经成功地使用下面的代码本身运行了类似“show version”的命令。请帮忙 脚本: name: / GET USERS / Get list of all the current users on switch action: junos_command args: { commands: 'sh

我有一个Ansible脚本,我只是使用junos_命令模块从Juniper switch获取用户列表,下面是我的代码片段。每当我尝试运行此程序时,都会收到RuntimeWarning。此外,我已经成功地使用下面的代码本身运行了类似“show version”的命令。请帮忙

脚本:

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}
错误:

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}
TASK[/GET USERS/GET当前交换机上所有用户的列表]***************
致命:[rlab-er1]:失败!=>{“changed”:false,“failed”:true,“module_stderr”:“/home/mbhadoria/.local/lib/python2.7/site packages/jnpr/junos/device.py:429:RuntimeWarning:CLI命令仅供调试使用!
\n警告。警告(\“CLI命令仅供调试使用!\”,RuntimeWarning)\n回溯(最近一次调用最后一次):
\n文件“/tmp/ansible\u lVOmPp/ansible\u module\u junos\u command.py\”,第261行,在
\n main()
\n文件\“/tmp/ansible\u lVOmPp/ansible\u module\u junos\u command.py\”,第233行,在main中
\append(xml_到_字符串(响应[索引])
\n文件“/tmp/ansible\u lVOmPp/ansible\u modlib.zip/ansible/module\u utils/junos.py\”,第79行,在xml\u-to\u字符串中\n文件“src/lxml/lxml.etree.pyx\”,第3350行,在lxml.etree.tostring中(src/lxml/lxml.etree.c:84534)\nTypeError:Type“str”无法序列化。
\n“,”模块\标准输出“:”消息“:”模块故障“,”已解析“:”假}”

junos_命令仅支持操作junos命令。您试图运行的是配置命令。因此,您会看到“显示版本”,它是运行命令,而不是“显示配置系统登录”

对于这样的配置数据,您应该使用带有junos_命令的rpc选项(获取配置)

junos_command:
rpcs:
  - "get_configuration
您还可以使用junos\u get\u config

或者朱诺

例:

任务[获取rpc运行]*********************************************************************************************************************************
......

重演*********************************************************************


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

警告只是一个警告。这里的错误消息是
TypeError:Type'str'无法序列化。
您应该在GitHub上提交一个问题,用于
junos_命令
模块。我也可以向GitHub提交一个问题,看看可以做些什么。谢谢非常感谢您的回复,我一直在玩junos_rpc甚至junos_cli,我做了与您提到的完全相同的事情,但不知为什么我的变量,在本例中,从未设置“junos”。请建议,看看我下面的例子。非常感谢name:Get system config 23 junos_rpc:24 host={{inventory_hostname}}27 rpc=Get config 28 filter_xml=”“29 dest=“user accounts.txt”30 register:curr_users_on_switch共享您正在使用的ansible和junos galaxy版本。我会相应地尝试。Junos版本型号:mx5-t Junos:13.3R8.7 Junos基本操作系统引导[13.3R8.7]Junos基本操作系统软件套件[13.3R8.7]ansible galaxy信息版本ansible galaxy 2.1.0.0希望这是您想要的。如果你想了解其他信息,请告诉我。非常感谢你的帮助,我是一个完全的新手,我会在明天回复你。