How it works...

We define all the data for all the interfaces in our sample network topology under two main data structures in the group_vars/all.yml file. We use the p2p_ip dictionary to model all the P2P IP addresses in our sample network, and we use the lo_ip dictionary to specify the loopback IP addresses for our nodes.

We use the junos_interface Ansible module to enable the interfaces and set the basic parameters for the interfaces, such as MTU and description. We loop over the p2p_ip data structure for each device, and we set the correct parameters for each interface on all the devices in our network inventory. We use the junos_l3_interface Ansible module to set the correct IPv4 address on all the interfaces in our sample network topology across all the devices.

Once we run the playbook, we can see that the interfaces are configured as required, as shown on the mxpe01 device:

Ansible@mxpe01# show interfaces
ge-0/0/0 {
description "peer:mxp01 remote_port:ge-0/0/0";
mtu 1500;
unit 0 {
family inet {
address 10.1.1.3/31;
}
}
}
ge-0/0/1 {
description "peer:mxp02 remote_port:ge-0/0/0";
mtu 1500;
unit 0 {
family inet {
address 10.1.1.9/31;
}
}
}