Ansible and IOSXE - NETCONF


In this blog post, we used Ansible to interact with our IOS XE devices through a module called ios-modules. However, it’s also possible to interact with our IOS XE devices through Ansible and Netconf, through the netconf module. Check the documentation here.

For all the examples, we will use a Cisco sandbox environment delivered by Cisco Devnet. To get a list of all sandboxes, check out this link. For this blog post, we will use the IOS XE sandbox.

Create interface

Similar to what we did in this post, we will add an interface to our IOSXE device but using the netconf_config module.

The key part in below snippet is the content part. This contains the YANG filter to create the interface on the IOS XE device. In case you wonder where this XML comes from, I would refer you to an earlier post on this topic, see here. The XML we are using in below Ansible playbook is exactly the same as what you would use to configure an interface using plain netconf.

- name: Add interface to IOSXE
  hosts: iosxe
  connection: local
  gather_facts: False

    - set_fact:
        ansible_connection: local

    - name: Create a loopback Loopback100 with NETCONF
        host: "{{inventory_hostname}}"
        port: "{{netconf_port}}"
        username: "{{ansible_user}}"
        password: "{{ansible_password}}"
        hostkey_verify: False
        content: |
              <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
                  <description>Pod Number 100</description>
                  <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">
                  <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">

Short post this time. Have a look at the Github repo to see the example.