如何过滤输出-Ansible的Junos Automation

时间:2018-07-06 23:26:32

标签: ansible junos-automation

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

我的搜索是在配置->路由-实例->实例->名称-> MY RI和所有具有MY RI的行中的路由实例 我对Filter和传递的kwarg没问题,但是我遇到了问题。

代码:

---
- 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名称的所有行

1 个答案:

答案 0 :(得分: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>