ansible - 为什么即使条件正确,Ansible 也会跳过任务?
问题描述
下面是我的代码,我在其中查找文件 /home/xxx/logs/213079.txt 中的值并使条件为真或假。
- name: register name
shell: cat /home/xxx/213079.txt
register: a213079
- name: register output
shell: cat /home/xxx/logs/213079.txt
register: h213079
- shell: echo {{ a213079.stdout }} Healthy >> /home/xxx/ABC/213079.txt
when:
- "'Serious' not in h213079.stdout"
- "'Service' not in h213079.stdout"
- shell: echo {{ a213079.stdout }} Faulty >> /home/xxx/ABC/213079.txt
when:
- "'Serious' in h213079.stdout"
- "'Service' in h213079.stdout"
但是当我运行相同时,所有条件都在跳过。
TASK [tmp : register output] *******************************************************************************************************************************************
changed: [127.0.0.1]
TASK [tmp : shell] *****************************************************************************************************************************************************
skipping: [127.0.0.1]
TASK [tmp : shell] *****************************************************************************************************************************************************
skipping: [127.0.0.1]
TASK [tmp : shell] *****************************************************************************************************************************************************
skipping: [127.0.0.1]
TASK [tmp : shell] *****************************************************************************************************************************************************
skipping: [127.0.0.1]
有人可以帮忙吗。
解决方案
因为我们不知道你得到的输出,所以这看起来很复杂,但如果你可以 grep 特定的词,我建议你使用类似下面的东西。
当:h213079.stdout =!“严重”和 h213079.stdout=!“服务”
何时:h213079.stdout ==“严重”和 h213079.stdout==“服务”
推荐阅读
- python - Celery:我可以使用 Celery 一次执行一个函数实例吗?
- sql - 如果行以 \ 结尾,则 sp_executesql 失败
- c# - WinForms 应用程序中的 Windows 10 ToastNotification
- node.js - 无法在分区中设置检查点
- c# - SMTP 电子邮件在本地工作,但不适用于 Devops
- python - 如何在 0815 开始 celery 周期性任务并在 django 中每 15 分钟运行一次
- konvajs - 如何改变变压器旋转图标的位置
- android - 原因:javax.xml.bind.UnmarshalException:无法创建 com.android.repository.impl.generated.v1.TypeDetails Android 的实例
- python - 使用 pandas 合并两个数据框
- c++ - 防止 lambda 的返回类型扣除