-1

I have a regex that matches everything after a certain word. When I call this pattern_match in my playbook I get the following error:

*ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to be in '/etc/ansible/REGEX.yml': line 12, column 6, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:*

           show int bundle-ether 21 | inc clearing
   - name: get time
     ^ here

The code is below:

---
- hosts: SCRING
  gather_facts: true
  connection: network_cli

  tasks:

   - name: show int | inc clearing
     iosxr_command:
       commands:
           show int bundle-ether 21 | inc clearing
   - name: get time
     pattern_match:
       regex: "(?<=counters ).*$"
     export: yes
     register: last
   - debug:
       msg: "{{ inventory_hostname }} counters last cleared - {{ last }}"
marky23
  • 1
  • 2
  • I have never heard of the `pattern_match` module for ansible and my search right now did not gather any results. It looks like your local ansible installation does not know that module either. Where did you take this example from ? Are you sure you are not missing a custom module provided by a role somewhere in a library folder ? – Zeitounator Oct 30 '19 at 17:43
  • Here is one of the examples I found - https://termlen0.github.io/2018/07/15/observations/ – marky23 Oct 31 '19 at 12:36
  • Also from Ansible - from Ansible - https://github.com/ansible-network/network-engine/blob/devel/docs/user_guide/command_parser.md#sample-playbooks – marky23 Oct 31 '19 at 13:09
  • I read over these again, ha. And it looks like the only way to use pattern_match is to call a seperate file with the parsing from your playbook that runs the IOS commands and debugs the output (or writes to a new file). Working on this now. – marky23 Oct 31 '19 at 14:55

2 Answers2

0

i suspect the syntax issue at "command".. can you try as below.

commands: show int bundle-ether 21

or

commands:
    - show int bundle-ether 21

added hyphen (-) for command in second try..

Sai
  • 166
  • 1
  • 8
0

I was able to get this running by creating a separate yaml file for parsing.

See below:

- name: parser meta data
  parser_metadata:
    version: 1.0
    command: show int bundle-ether 20 | inc clearing
    network_os: iosxr


- name: get time
  pattern_match:
    regex: "(?<=counters ).*$"
    match_all: yes
  register: last
  export: yes

AND

---
- hosts: SCRING
  gather_facts: false
  connection: network_cli


  roles:
    - ansible-network.network-engine


  tasks:

   - name: show int | inc clearing
     iosxr_command:
       commands:
         - show int bundle-ether 20 | inc clearing
     register: clearing

   - name: PARSE
     command_parser:
       file: "parser_templates/last_cleared.yml"
       content: "{{ clearing.stdout[0] }}"

   - debug:
       msg: "{{ inventory_hostname }} counters last cleared - {{ last }}"

It did not buy me much, the output looks like this:

msg: 'CHS_ASR counters last cleared - [{''matches'': u''1w1d''}]'

If I could get the brackets and 'matches' statement out of there I would be good.

marky23
  • 1
  • 2