-1

我有一个匹配某个单词后所有内容的正则表达式。当我在我的剧本中调用这个 pattern_match 时,我收到以下错误:

*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

代码如下:

---
- 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 }}"
4

2 回答 2

0

我能够通过创建一个单独的 yaml 文件进行解析来运行它。

见下文:

- 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 }}"

它并没有给我买多少,输出看起来像这样:

msg: 'CHS_ASR 计数器上次清除 - [{''matches'': u''1w1d''}]'

如果我能从那里得到括号和“匹配”声明,我会很好。

于 2019-10-31T15:41:03.780 回答
0

我怀疑“命令”的语法问题..你可以尝试如下。

commands: show int bundle-ether 21

或者

commands:
    - show int bundle-ether 21

在第二次尝试中为命令添加了连字符 (-)。

于 2019-10-30T18:41:27.263 回答