0

我的代码的目的是从配置中过滤特定的路由实例名称。

我的搜索是在 configuration-> Routing -Instances->Instance -> name -> MY RI 中的路由实例以及所有具有 MY RI 的行我对 Filter 和传递 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 名称的行

4

1 回答 1

0

假设设备低于配置

# 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 选项。过滤器可以用作

filter_xml: <routing-instances><instance><name>pqr</name></instance></routing-instances>
于 2018-07-09T09:33:59.320 回答