How it works...

We build the Ansible inventory using the hosts file and we define multiple groups in order to group the different devices in our network infrastructure, as follows:

  • We create the PE group, which references all the MPLS Provider Edge (PE) nodes in our topology.
  • We create the P group, which references all the MPLS Provider (P) nodes in our topology.
  • We create the junos group, which references all the devices running Junos OS as the OS.
  • We create the core parent group, which references both the PE and P groups.

Finally, we create the Ansible.cfg file and configure it to point to our hosts file, to be used as the Ansible inventory file. We set the gathering to explicit in order to disable the setup module, which runs by default to discover facts for the managed hosts. Disabling the setup module is mandatory since the setup module will fail when run against network devices.

We can validate that our Ansible inventory is structured and written correctly by typing the following command:

$ Ansible-inventory --list

"all": {
"children": [
"core",
"junos",
"ungrouped"
]
},
"core": {
"children": [
"p",
"pe"
]
},
"junos": {
"hosts": [
"mxp01",
"mxp02",
"mxpe01",
"mxpe02"
]
},
"p": {
"hosts": [
"mxp01",
"mxp02"
]
},
"pe": {
"hosts": [
"mxpe01",
"mxpe02"
]
}