Ansible Project: IP to Physical Port Mapping

This is a mini project I created for myself in one of my previous roles. The problem, that it is designed to solve is given an IP address, where is that IP physically located?

This is necessary in older network environments that aren’t using tools such as Solarwinds, or newer products like; Cisco ISE, DNA Centre or ACI. Each of these tools/products has the ability store a database of IP/port/switch info atleast. An IP can be easily looked up in a web interface.
However if these tools/products are not yet in use or not correctly utilised then it can be time consuming to search for a IP and then MAC address on each switch.

This is where my Ansible tool comes in handy. It runs the commands that you would manually, but in automatically. All the user needs to do is to enter the IP address they are looking for.

The topology is not exactly like it would be setup in a modern environment. In my GNS3 lab I am using a “router on a stick” or 802.1q tagging on the router. This is because the IOS layer 3 switch images I have do not work correctly. So my switches will be all layer 2 and the router is the gateway. The topology is not the important factor here.

There are two DHCP pools configured on the router to make testing easy and show how moving the clients (which are IOS router images) moves the MAC address and therefore changes Ansible output.

Manual Process

In this scenario I want to locate the physical port that client 1 is on. I know that R1 will be the gateway and so I can get the ARP which shows me the MAC address.
With the MAC address I can check both switches to see the physical port.

Ansible

The Ansible output I have is not pretty and you need to have an idea what to look for. However it is there without going through the manual process.

The playbook and all files can be found on my Github.

The IP to be checked is 10.20.1.3. This IP resides on SW3, 172.16.1.103. The output we are looking for is a MAC address found on all switches on the uplink ports and the MAC address found on a user port.

Now there will be problems if all the switches in use use random ports as their uplink ports. However this should not be the case and in the lab eth3/3 is the uplink port.

Fixing the Output

In the output above every switch returns the location of the MAC address.. I have updated the playbook to only show the MAC address when the port is not on the known uplink port of Eth3/3. Below is a excerpt of th eplaybook containing on the the lines for the debug output.

Leave a Comment

Your email address will not be published. Required fields are marked *