【问题标题】:Trouble running pattern match on cisco iosxr command in Ansible在 Ansible 中的 cisco iosxr 命令上运行模式匹配时出现问题
【发布时间】:2020-02-25 22:58:53
【问题描述】:

我有一个正则表达式可以匹配某个单词之后的所有内容。当我在剧本中调用此 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 }}"

【问题讨论】:

  • 我从未听说过用于 ansible 的 pattern_match 模块,我现在的搜索没有收集到任何结果。看起来您的本地 ansible 安装也不知道该模块。你是从哪里得到这个例子的?您确定您没有丢失库文件夹中某个角色提供的自定义模块吗?
  • 这是我找到的一个例子 - termlen0.github.io/2018/07/15/observations
  • 我又读了一遍,哈。看起来使用 pattern_match 的唯一方法是调用一个单独的文件,该文件从你的 playbook 中运行 IOS 命令并调试输出(或写入新文件)。现在正在处理这个问题。

标签: parsing networking ansible cisco ansible-galaxy


【解决方案1】:

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

commands: show int bundle-ether 21

commands:
    - show int bundle-ether 21

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

【讨论】:

  • 不幸的是,这些都没有运气。同样的错误。
【解决方案2】:

我能够通过创建一个单独的 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''}]'

如果我能去掉括号和“匹配”语句,我会很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 2011-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多