首页 > 解决方案 > 如何正确使用 failed_when?

问题描述

在我的剧本中,我的任务很少,其中一项与调试步骤有关。

任务 :

- debug:
    msg: "File found"
  when: file.stat.exists

- debug:
    msg: "File not found"
  failed_when: not file.stat.exists

问题

标签: ansible

解决方案


如果您想在某个条件下使播放失败,请使用失败模块

- stat:
    path: /path/to/file
  register: st

- fail:
    msg: "File not found"
  when: not st.stat.exists

推荐阅读