Skip to content

add # of successful matches to verbose output of textfsm and text_parser #60

Description

@acozine

As a user, If I make a mistake in a matching directive or in the content: parameter, I may end up with one or more null values in the final variable output. For example, this playbook:

---
- hosts: ios
  connection: network_cli
  gather_facts: no

  tasks:
  - name: Collect version information from device
    ios_command:
      commands: "show version"
    register: ios_version_output

  - import_role:
      name: ansible-network.network-engine

  - name: Generate version facts as JSON
    text_parser:
      file: "my_parsers/ios_show_version.yaml"
      content: ios_version_output['stdout_lines'][0]
#  in case anyone find this while looking for a *correct* example
#  the correct formulation would be 
# content: "{{ ios_version_output.stdout.0 }}"

  - name: Display matches (system_facts)
    debug:
      var: system_facts 

succeeds, but returns this final variable:

ok: [ios01] => {
    "system_facts": {
        "image_file": null, 
        "memory": {
            "free": null, 
            "total": null
        }, 
        "model": null, 
        "uptime": null, 
        "version": "null"
    }
}

The error in this example is in the content line, but a similar situation could occur if one or more match rules were incorrect. If I run the playbook with -vvvv I can see the directives:

processing directive: match version
processing directive: match model
processing directive: match image
processing directive: match uptime
processing directive: match total memory
processing directive: match free memory
processing directive: export system facts to playbook

but there's no information about which ones find matches.

To help debug issues with content lines and issues with match definitions, could we:

  • add "found match" or "no match" to verbose output for each directive processed
  • add information on total matches (for example, "7 matches found out of 8 match directives processed" - I'm not sure what level of verbosity should be required for this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions