我有一个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}发布于 2016-08-31 10:13:12
junos_command只支持junos操作命令。您要运行的是配置命令。因此,您可以看到“显示版本”,这是操作命令工作,而不是“显示配置系统登录”。
对于这样的配置数据,您可以在junos_command中使用rpc选项(get- configuration )。
junos_command:
rpcs:
- "get_configuration您也可以使用junos_get_config。
config.html
或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 : ok=1 changed=1 unreachable=0 failed=0
https://stackoverflow.com/questions/39238026
复制相似问题