Network automation lab 7 of 27

Parse CLI output with TextFSM, ntc-templates and TTP

Turn show-command text into structured data: ntc-templates for interfaces, OSPF and CDP, a TextFSM template you write yourself, and a TTP template for the running configuration, then use the results to validate the design and enforce an SSH policy.

Run this lab

It needs Lite: its 4 nodes are set to 4 vCPU and 2,560 MB in total. That fits the free demo too.

In your workspace: Shared, then Network Automation - CCNA and CCNP Automation guided labs, then 07 - Parse CLI output with TextFSM ntc-templates and TTP

Try it free for 30 minutesRun it on Lite from £3 a day

The free demo needs no card and no email. Every lab plan includes every guided lab.

Level
Intermediate
Time
About 85 minutes
Nodes need
4 vCPU, 2,560 MB
Smallest plan
Lite

The scenario

Kestrel Freight's design document says the branch triangle has four links, every OSPF adjacency should be FULL, and SSH must follow the security policy (version 2, a 60-second login timeout, at most 2 retries). Nobody knows if that's true. You'll collect the routers' output once, turn it into structured data with three kinds of parser, and produce evidence: which links exist, whether OSPF is healthy, which routers break the SSH policy (then fix them), and which interfaces are missing descriptions.

RouterMgmt (Gi0/0)Gi0/1Gi0/2Loopback0
r110.10.20.1110.1.12.1/30 → r210.1.13.1/30 → r310.255.0.1
r210.10.20.1210.1.12.2/30 → r110.1.23.1/30 → r310.255.0.2
r310.10.20.1310.1.13.2/30 → r110.1.23.2/30 → r210.255.0.3

All three run OSPF area 0 on their links and loopbacks. Files in ~/lab: collect.py (ready to use), design.yaml (the documented links and the SSH policy), parsers.py (helpers with TODOs) and an empty templates/ folder. Login netops / NetOps-Lab1.

What you’ll practise

  • Explain why screen-scraping needs a parser and when regular expressions stop being enough
  • Parse IOS show commands into lists of dictionaries with ntc-templates
  • Validate a documented topology against live CDP neighbours and check every OSPF adjacency
  • Write and debug your own TextFSM template, then use it to audit and remediate SSH settings
  • Parse configuration text with a TTP template

The tasks

  1. Collect once, parse many times
  2. Why a parser? Regex versus TextFSM
  3. Check every OSPF adjacency
  4. Validate the design with CDP
  5. Read the output you need to parse yourself
  6. Write a TextFSM template, audit and fix SSH
  7. Parse configuration with TTP

The Lab Tasks pane has the scenario, these tasks, the checks to run, hints and the full solution.

Topology and devices

The network as it opens in EVE-NG, drawn from the lab’s own canvas, and the image each node runs.

Topology of Parse CLI output with TextFSM ntc-templates and TTP4 nodes and 1 network, 7 links. Every link is listed as text below the diagram.devboxr1r2r3Mgmteth0Gi0/1Gi0/1Gi0/2Gi0/2Gi0/0Gi0/0Gi0/2Gi0/1Gi0/0
4 nodes and 1 network, with the interface names each link uses. On a narrow screen, scroll the diagram sideways.
Nodes in Parse CLI output with TextFSM, ntc-templates and TTP, with the image each runs and the vCPU and RAM it’s set to
NodeDeviceImage in Add NodeSet to
devboxEVE-NG GUI server (Docker)eve-gui-server:latest1 vCPU, 1,024 MB
r1Cisco IOSvvios-adventerprisek9-m.spa.159-3.m91 vCPU, 512 MB
r2Cisco IOSvvios-adventerprisek9-m.spa.159-3.m91 vCPU, 512 MB
r3Cisco IOSvvios-adventerprisek9-m.spa.159-3.m91 vCPU, 512 MB

How to open this lab

  1. Sign in to your workspace at lab.cloudlabbox.com.

  2. In File Manager, open Shared, then the folder Network Automation - CCNA and CCNP Automation guided labs.

  3. Open 07 - Parse CLI output with TextFSM ntc-templates and TTP and start its nodes, then open Lab Tasks for the scenario and the steps.

The lab is read-only. You can start the nodes and configure the devices, but changes to the topology can’t be saved. To change it, rebuild it in your own folder.

More Network automation labs

All Network automation labs

Related labs in other courses

CloudLabBox is independent of Cisco. The lab follows exam topics and isn’t vendor training material; vendor names identify the exams and the images in the workspace.