Network Automation using YANG Models across XE, XR, & NX

Ansible NETCONF Plugin

Ansible Networking has had a NETCONF plugin developed and available since Ansible release 2.3. This plugin is a connection plugin that is used with ansible_connection, thus, it replaces using the network_cli value. Like you just connected to each of your NETCONF enabled devices, this plugin connects to the same service on the network device using ssh. Once the connection is established, RPCs can be made to the network device over NETCONF. It is worth noting that this plugin has dependencies an open source library called ncclient, thus this library must be installed on Ansible client, i.e. within your Docker container.

The documentation for this plugin can be found here: Ansible NETCONF Plugin

View Second Ansible Playbook Skeleton

You are now going to finish building out another Ansible playbook that utilizes the NETCONF plugin with a directory structure very similar to the previous playbook you created in the previous section where you used Ansible for CLI automation to enable MDP interfaces (NETCONF and RESTCONF).

This second playbook skeleton was pulled from the Git repo when you performed a git clone in the previous lab and is found in your /workspace/playbooks/mdp_netconf/ directory.

As previously, you can view this playbook directory structure using tree /workspace/playbooks/mdp_netconf/.

        
            cd /workspace/playbooks/mdp_netconf/
            tree /workspace/playbooks/mdp_netconf/
            
  •         
                [root@25ef0c91db80 playbooks]# tree /workspace/playbooks/mdp_netconf/
                /workspace/playbooks/mdp_netconf/
                |-- ansible.cfg
                `-- roles
                    |-- nx-netconf
                    |   |-- README.md
                    |   |-- defaults
                    |   |   `-- main.yml
                    |   |-- files
                    |   |   `-- main.yml
                    |   |-- handlers
                    |   |   `-- main.yml
                    |   |-- meta
                    |   |   `-- main.yml
                    |   |-- tasks
                    |   |   `-- main.yml
                    |   |-- tests
                    |   |   |-- inventory
                    |   |   `-- test.yml
                    |   `-- vars
                    |       `-- main.yml
                    |-- xe-netconf
                    |   |-- README.md
                    |   |-- defaults
                    |   |   `-- main.yml
                    |   |-- files
                    |   |   `-- main.yml
                    |   |-- handlers
                    |   |   `-- main.yml
                    |   |-- meta
                    |   |   `-- main.yml
                    |   |-- tasks
                    |   |   `-- main.yml
                    |   |-- tests
                    |   |   |-- inventory
                    |   |   `-- test.yml
                    |   `-- vars
                    |       `-- main.yml
                    `-- xr-netconf
                        |-- README.md
                        |-- defaults
                        |   `-- main.yml
                        |-- files
                        |   `-- main.yml
                        |-- handlers
                        |   `-- main.yml
                        |-- meta
                        |   `-- main.yml
                        |-- tasks
                        |   `-- main.yml
                        |-- tests
                        |   |-- inventory
                        |   `-- test.yml
                        `-- vars
                            `-- main.yml
    
                25 directories, 28 files
    
            
        

    Create Host & Connection File

    Create the host file below that contains the information Ansible will use to connect to your devices. Again, you'll notice the host file below makes use of device groups; [xe], [xr], and [nx], that is used to group the different platforms. Like before, ansible_user and ansible_ssh_pass is used to provide the username and password. This time, ansible_connection is set to use Ansible's netconf plugin that relies on an open-source library called ncclient. You'll be looking at that library in the next section of the lab.

    The ansible_network_os again specifies the platform, but in the context of the plugins ncclinet supports.

    The change in ansible_network_os for IOS goes to csr. While there is an ios paramater for ncclient, since we're using a CSRv in this lab, we'll stick with the csr parameter as it is geated more toward IOSXE.

    The change in ansible_network_os for IOSXR goes to default. Nclient does not have an iosxr defined pattern, thus, the default will need to be used for XR platforms.

    The ansible_network_os for NX stays the same; nxos.

            
                cat <<EOF >> /workspace/playbooks/mdp_netconf/hosts
                # hosts file for Ansible playbook mdp_netconf
    
                [all:vars]
                ansible_user=admin
                ansible_ssh_pass=cisco.123
                ansible_connection=netconf
    
                [xe]
                10.2.100.11     ansible_network_os=csr
    
                [xr]
                10.2.100.12     ansible_network_os=default
    
                [nx]
                10.2.100.13     ansible_network_os=nxos
    
                EOF