ansible - 在 sdout 中匹配通配符时如何使 Ansible 失败?
问题描述
我正在使用 shell 命令运行 SQL,输出为:
SQL*Plus: Release 10.1.0.4.0 - Production on Thu Sep 6 15:44:35 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
<b>
ERROR:
ORA-12560: TNS:protocol adapter error
</b>
我正在使用以下方法检查 std 中的错误:
- hosts: localhost
tasks:
- name: error-codes
shell: "cat {{ item }}"
with_items:
- file1.txt
- file2.txt
register: result
failed_when: "'ERROR' in result.stdout"
但是,我需要匹配多行,例如
ERROR:
ORA-
标准输出是单行,所以我尝试使用通配符进行匹配,但它似乎不匹配
failed_when: "'ERROR.*ORA' in result.stdout"
使用通配符时如何使其失败?
解决方案
result.stdout
不是单行内容。它是一个多行内容,它显示在一行中。
这里(?s)
将regex_search
整个记录视为一行。
result.stdout| regex_search("(?s)ERROR.*ORA")
推荐阅读
- python - 如何同时使用 DataFrameIterator 和 TensorSliceDataset 进行混合数据的训练?
- laravel - 在 Laravel 中使用 Model::Find 进行单元测试
- python-3.x - python 中的 int('1.5') VS float('1.5')
- html - 从 IE 切换到 EDGE 后样式表出现问题。背景颜色偏移
- python - 如何使用 datetime 将 int 转换为时间
- php - 来自整数值的 PHP DateTime
- typescript - 用 ES2015 模块替换 TypeScript 命名空间
- javascript - 警告:渲染不同组件时无法更新组件。反应JS
- nim-lang - 从图像文件创建颜色直方图
- python - 如何将 UTF-16-LE txt 文件转换为 ANSI txt 文件并删除 PYTHON 中的标头?