Ansible Switch Basics - PTM and LLDP


Userlevel 1
The goal of this article is to provide a set of Ansible tasks to cover the basics of an initial switch setup. These tasks are typically run once when the switch is initially provisioned.
The assumption is you have Ansbile installed on a server that can reach the switch management network and that you have a basic understanding of Ansible. The examples below make use of only Ansible core modules so a default Ansible installation should work fine.
Details on PTM and Setup
Setting up PTM (Prescriptive Topology Manager) on the switch helps validate proper cabling in the data center. PTM uses LLDP neighbor information to determine if the connections are correct by comparing the actual output to the desired connections as defined in a topology file. The topology file is a list of the connections in a DOT format for all of the devices in the network. As part of these tasks we will configure PTM by copying a topology file to the switch and then verify the connections through a few control commands.
Ansible Tasks
  • Copy the topology file to the switches
  • Restart the PTM service
  • Validate the PTM connections
  • Validate the LLDP neighbors
#Copy the topology file to the remote switches
- name: configure ptmd topology.dot
copy: src=topology.dot dest=/etc/ptm.d/topology.dot
tags:
- ptm_setup
- initial_setup

#Restart the PTM service to read in the new topology file
- name: Restart ptmd service
service: name=ptmd state=restarted
tags:
- ptm_setup
- initial_setup

#Poll the PTM service for the current state and details of the connections
- name: Check PTM status
command: ptmctl -d
register: ptmctl_output
tags:
- ptm_setup
- initial_setup

#Print out the results (Note in the command above you could use JSON output by adding -j)
- name: Print PTM table
debug: var=ptmctl_output.stdout.split('\n')
tags:
- ptm_setup
- initial_setup

#Pull the lldp neighbor table
- name: Check lldp neighbors
command: lldpctl
register: lldpctl_output
tags:
- ptm_setup
- initial_setup

#Print out the results (Note in the command above you could use JSON output by adding -f json)
- name: Print lldp neighbors
debug: var=lldpctl_output.stdout.split('\n')
tags:
- ptm_setup
- initial_setup
Example of a topology file to describe a full mesh 2 leaf 2 spine network with 2 wan devices connected to the spines.
cumulus@leaf1$ cat /etc/ptm.d/topology.dot
graph G {
graph [hostidtype="hostname", version="1:0"];
"leaf1":"swp51" -- "spine1":"swp1";
"leaf1":"swp52" -- "spine2":"swp1";
"leaf2":"swp51" -- "spine1":"swp2";
"leaf2":"swp52" -- "spine1":"swp2";
"spine1":"swp31" -- "wan1":"swp49";
"spine1":"swp32" -- "wan2":"swp49";
"spine2":"swp31" -- "wan1":"swp50";
"spine2":"swp32" -- "wan2":"swp50";
} For more information on installing Ansible, Ansible modules, and PTM used in these examples

3 replies

Userlevel 2
Quick edit:

This:
#Copy the topology file to the remote switches- name: configure ptmd topology.dot

Needs edited to this:
#Copy the topology file to the remote switches
- name: configure ptmd topology.dot
Userlevel 1
Whoops formatting error thanks for catching that. Updated the post.
Is there any way to take that information and populate the interface alias information.

Reply