How it works...

In order to start interacting with the Junos OS devices via NETCONF, we need to enable it first, therefore we need to SSH into the device initially and enable NETCONF. That is why we are using the network_cli Ansible connection in order to connect with the Junos OS devices via traditional SSH. In order to use the network_cli connection plugin, we need to set Ansible_network_os as junos.

Since we are going to use the NETCONF API in all interactions with Juniper devices in all coming recipes, we enabled the network_cli plugin only for the junos_netconf task in this playbook via the vars attribute. However, for all future tasks that we will add in this playbook, we will use the netconf connection specified in the Ansible_connection attribute in the group_vars/junos.yml file.

We create a new playbook called pb_jnpr_net_build.yml, and in the first task, we use the junos_netconf module to enable the NETCONF protocol on the remote Junos OS devices. We state the NETCONF port that will be used (by default, it is 830), and we outline that this configuration must be present on the remote devices via the state: present directive.

Once we run the playbook, we will see that all the Junos OS devices are configured with NETCONF, as shown in the following code:

admin@mxpe01# show system services
SSH;
netconf {
SSH {
port 830;
}
}