ansible - Failed_when module with OR
问题描述
I'm trying to handle errors in my playbook, precisely, I want to be able to ignore a specific error. The message that I want to "accept" is contains the phrase "already exists". In order to get that to work, I need an OR statement, as I also want to accept successful task execution.
[...]
register: command_result
failed_when: not ("already exists" in command_result.msg or "CALL" in command_result.statusmessage)
The problem is, the task is accepted when the error message consists "already exists", as I wished, however, "CALL" in statusmessage is not working - meaning the task fails even if the statusmessage is exactly that. There must be something wrong with my or statement. I've tried:
"'already exists' in command_result.msg or 'CALL' in command_result.statusmessage"
But that does not work as well.
What is important: when a task returns an error, command_result.statusmessage is empty - "command_result.statusmessage": "VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'statusmessage'"
. Could it be the reason for the following error?
"The conditional check '('already exists' not in command_result.msg) or ('CALL' in command_result.statusmessage)' failed. The error was: error while evaluating conditional (('already exists' not in command_result.msg) or ('CALL' in command_result.statusmessage)): Unable to look up a name or access an attribute in template string
I was hoping that it just parses the string "VARIABLE IS NOT DEFINED!". How can I resolve my issue then?
解决方案
问:“command_result.statusmessage”:“变量未定义!:'dict object'没有属性'statusmessage'”
A:默认情况下,给属性添加一个空字符串statusmessage
。例如
failed_when: not (('already exists' in command_result.msg) or
('CALL' in command_result.statusmessage|default('')))
推荐阅读
- python - 在 Gitlab 中配置 .gitlab-ci.yml 文件来测试 python 代码
- java - Spring-boot 应用程序在执行器端口上抛出错误
- datastage - 在 Datastage 中找不到 DSHOME
- c++ - ADODB 记录集中的访问冲突关闭
- mysql - MySQL 中的多个 WHERE/AND 子句是否按顺序检查?如果第一个为假,是否会跳过后续检查?
- mysql - SQL:计算引用表自身 id 的行数
- javascript - 如何检索保存的 id 然后在 jquery 中作为选定的测试通过
- angular - 使用谷歌登录不会在移动设备上重定向,但可以在浏览器上使用 - 带有 firebase 的 Ionic3
- c# - 请求数据更改时强制重新加载 .NET Core 2.1 中的 ResponseCache
- assembly - 汇编程序我如何才能访问数组的元素?