Ansible中的ios iosxr命令上的运行模式匹配错误

问题描述 投票:0回答:2

我有一个正则表达式,可以匹配某个单词后的所有内容。当我在剧本中调用此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 }}"
parsing networking ansible cisco ansible-galaxy
2个回答
0
投票

我怀疑“命令”处的语法问题。您可以尝试以下操作。

commands: show int bundle-ether 21

commands:
    - show int bundle-ether 21

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


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

它没给我买很多东西,输出看起来像这样:

消息:'CHS_ASR计数器最后被清除-[{''matches'':u''1w1d''}]'

如果我能得到方括号和'matches'陈述,那会很好。

© www.soinside.com 2019 - 2024. All rights reserved.