我有一个Ansible脚本,我只是使用junos_command模块从Juniper交换机获取用户列表,下面是我的代码片段。每当我尝试运行它时,我都会继续运行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}
答案 0 :(得分:2)
junos_command仅支持操作junos命令。您要运行的是配置命令。因此,您会看到“show version”,它是可操作的命令,但不是“show configuration system login”。
对于此类配置数据,您可以使用带有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:ok = 1 changed = 1 unreachable = 0 failed = 0