如何过滤输出 - Junos Automation with Ansible
How to filter the output- Junos Automation with Ansible
我的代码的目的是从配置中过滤特定的路由实例名称。
我的搜索是在配置中的路由实例->路由-实例->实例->名称->我的RI和所有具有我的RI的行
我对 Filter 和 passing kwargs 没问题,但我遇到了问题。
代码:
---
- name: Get RI
hosts: junos Host
connection: local
gather_facts: no
roles:
- Juniper.junos
tasks:
- name: send rpc with args
juniper_junos_rpc:
host: "{{ inventory_hostname }}"
user: "user"
passwd: "pssword!"
rpc: get-config
logfile: 'rpc.log'
format: xml
dest: "{{ inventory_hostname }}.xml"
kwargs:
filter_xml: configuration/routing-instances/instance/name = CSP-RI-L2-cc6abb1d-63ab-483f-b4ce-f4b978c877cc
**ERROR**
error:fatal: [sit-entce.tlab.equinix.com]: FAILED! => {
"changed": false,
"module_stderr": "/usr/lib/python2.7/dist-packages/Crypto/Cipher/blockalgo.py:141: FutureWarning: CTR mode needs counter parameter, not IV\n self._cipher = factory.new(key, *args, **kwargs)\nTraceback (most recent call last):\n File \"/tmp/ansible_T0LCbD/ansible_module_juniper_junos_rpc.py\", line 622, in <module>\n main()\n File \"/tmp/ansible_T0LCbD/ansible_module_juniper_junos_rpc.py\", line 518, in main\n options=attr, **kwarg)\nTypeError: get_config() got multiple values for keyword argument 'filter_xml'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
任何建议。那里会有多个 RI,我必须搜索一个 RI 并打印它或存储所有具有该 RI 名称的行
假设设备低于配置
# show | compare | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.1I0/junos">
<configuration>
<routing-instances operation="create">
<instance>
<name>pqr</name>
<interface>
<name>ge-0/0/2.0</name>
</interface>
</instance>
<instance>
<name>xyz</name>
<interface>
<name>ge-0/0/1.0</name>
</interface>
</instance>
</routing-instances>
</configuration>
现在如果你想过滤一个非常具体的实例,你可以使用过滤器选项。
过滤器可以用作
filter_xml: <routing-instances><instance><name>pqr</name></instance></routing-instances>
我的代码的目的是从配置中过滤特定的路由实例名称。
我的搜索是在配置中的路由实例->路由-实例->实例->名称->我的RI和所有具有我的RI的行 我对 Filter 和 passing kwargs 没问题,但我遇到了问题。
代码:
---
- name: Get RI
hosts: junos Host
connection: local
gather_facts: no
roles:
- Juniper.junos
tasks:
- name: send rpc with args
juniper_junos_rpc:
host: "{{ inventory_hostname }}"
user: "user"
passwd: "pssword!"
rpc: get-config
logfile: 'rpc.log'
format: xml
dest: "{{ inventory_hostname }}.xml"
kwargs:
filter_xml: configuration/routing-instances/instance/name = CSP-RI-L2-cc6abb1d-63ab-483f-b4ce-f4b978c877cc
**ERROR**
error:fatal: [sit-entce.tlab.equinix.com]: FAILED! => {
"changed": false,
"module_stderr": "/usr/lib/python2.7/dist-packages/Crypto/Cipher/blockalgo.py:141: FutureWarning: CTR mode needs counter parameter, not IV\n self._cipher = factory.new(key, *args, **kwargs)\nTraceback (most recent call last):\n File \"/tmp/ansible_T0LCbD/ansible_module_juniper_junos_rpc.py\", line 622, in <module>\n main()\n File \"/tmp/ansible_T0LCbD/ansible_module_juniper_junos_rpc.py\", line 518, in main\n options=attr, **kwarg)\nTypeError: get_config() got multiple values for keyword argument 'filter_xml'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
任何建议。那里会有多个 RI,我必须搜索一个 RI 并打印它或存储所有具有该 RI 名称的行
假设设备低于配置
# show | compare | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.1I0/junos">
<configuration>
<routing-instances operation="create">
<instance>
<name>pqr</name>
<interface>
<name>ge-0/0/2.0</name>
</interface>
</instance>
<instance>
<name>xyz</name>
<interface>
<name>ge-0/0/1.0</name>
</interface>
</instance>
</routing-instances>
</configuration>
现在如果你想过滤一个非常具体的实例,你可以使用过滤器选项。 过滤器可以用作
filter_xml: <routing-instances><instance><name>pqr</name></instance></routing-instances>