ansible - 如何正确使用 failed_when?
问题描述
在我的剧本中,我的任务很少,其中一项与调试步骤有关。
任务 :
- debug:
msg: "File found"
when: file.stat.exists
- debug:
msg: "File not found"
failed_when: not file.stat.exists
问题
- 当我运行剧本时,我总是在我的屏幕文件上收到消息 not found但文件在那里......只有当文件不存在时,任务才会失败并显示此消息。
解决方案
如果您想在某个条件下使播放失败,请使用失败模块:
- stat:
path: /path/to/file
register: st
- fail:
msg: "File not found"
when: not st.stat.exists
推荐阅读
- python - 无法调用函数
- google-cloud-platform - GCP vpc相同的目的地,不同的路线
- python - 如何删除位置如此接近的两个节点之一
- android - 从服务发送 KeyEvent
- android - 如何获得响应吐司
- r - 安装 R 4.1.0 后,R 控制台工具栏和菜单中的字体不再正确
- css - bootsrap 5 内容重叠的粘性侧边栏问题
- cocoapods - 无法安装 cocoapods MacBook Air m1
- java - Windows 10 UDP 缓冲区大小/多播接收
- c# - MSB6006“csc.exe”退出代码-1073741819?