cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
479
Views
0
Helpful
0
Replies

NETCONF - Looping over interface types in XML response

charliepdean
Level 1
Level 1

Hi everyone,

I am banging my head against the wall on this one. I am writing an Ansible playbook using NETCONF that retrieves a list of interfaces that have an ACL configured and then using the XML response, create a new payload that removes the ACL. I am able to get the interfaces no problem using a XPath filter but I cannot figure out how to handle the multiple interface types when creating the payload to send back.

I am using Ansible's parse_xml filter to convert the XML response into a data structure I can then use to template out the XML payload. The issue I am having is I cannot figure out how to capture the interface type tag when parsing the XML. The only way I can make it work is to statically set the interface type (e.g. GigabitEthernet or FiveGigEthernet) and loop over that. The issue with that approach is I have to add every possible interface type to my playbook.

Has anyone done this before? Almost 100% of tutorials / examples for NETCONF show how to modify a single interface and nothing more advanced than that (maybe I'll write one when I figure this out :|)

Here's the xml spec for parse_xml filter I'm using (currently looping only over GigabitEthernet):

 

 

 

---
keys:
  result:
    value: "{{ interfaces }}"
    top: native/interface/GigabitEthernet
    items:
      name: name

vars:
  interfaces:
    name: "{{ item.name }}"

 

 

 

Here's the xml jinja template I'm using for the payload (this is an example, needs to be tweaked once parsing works) :

 

 

 

<target>
    <running/>
</target>
<config>
    <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
    <interface>
{% for itype,intfs in interfaces.output.data.native.interface.items() %}
{% for intf in intfs %}
        <{{ itype }}>
            <name>{{ intf.name }}</name>
            <ip>
                <access-group xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete"/>
            </ip>
        </{{ itype }}>
{% endfor %}
{% endfor %}
    </interface>
    </native>
</config>

 

 

 

 

0 Replies 0
Review Cisco Networking for a $25 gift card