Parsing Printouts with Ansible Regular Expression Filters

Ansible is great at capturing and using JSON-formatted data returned by REST API (or any other script or method it can invoke), but unfortunately some of us still have to deal with network devices that cannot even spell structured data or REST.

There are plenty of great open-source tools that help you parse text printouts, including TextFSM, ntc-ansible and NAPALM get functions, but sometimes you have to parse a printout that nobody bothered with before.

Ideally, you’d write a short Ansible plug-in (or Jinja2 filter) in Python to do the parsing, or you could go for a QDS (Quick-and-Dirty Solution) and extract the information directly in Ansible playbook with a Jinja2 regex filter.

Add comment
Sidebar