0

I'm using a textfsm filter inside a Jinja2 template to create a report. The textfsm filter can throw an exception, which stops the Jinja2 template from completing.

Below is how I call the textfsm filter in the Jinja2 template. The textfsm filter returns a list of dictionaries, which I print out in the template.

{% set structure = results.std_out[0] | parse_cli_textfsm(playbook_dir + '/template/cisco_ios_show_ip_arp.textfsm') %}

Is there a way to have the textfsm filter return a string of say 'ERROR' when an error occurs? I could then test for this and display an appropriate message. Basically, I'd like the template to complete despite the exception.

Greenjoy
  • 59
  • 2
  • 12
  • 1
    You could write a custom filter (just drop in into your `filter_plugins` directory) that handles exceptions the way you want. Maybe make exception handling behavior an option (e.g., `ignore`, `raise`, or `return_error`). – larsks Oct 17 '20 at 12:09
  • Another possible idea would be to use `set_fact` and so assign `structure: results.std_out[0] | parse_cli_textfsm(playbook_dir + '/template/cisco_ios_show_ip_arp.textfsm')` but nest this fact in a `block` and `rescue` it setting the fact `structure` to whatever error message you want – β.εηοιτ.βε Dec 01 '20 at 19:46

0 Answers0