Ansible 如何正确使用失败的_?

Ansible 如何正确使用失败的_?,ansible,Ansible,在我的剧本中,我有几个任务,其中一个与调试步骤有关 任务: - debug: msg: "File found" when: file.stat.exists - debug: msg: "File not found" failed_when: not file.stat.exists 问题 当我运行playbook时,我总是会收到屏幕上的消息“未找到文件”,但文件在那里。。。只有当文件不存在时,任务才会失败,并显示此消息

在我的剧本中,我有几个任务,其中一个与调试步骤有关

任务:

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

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

  • 当我运行playbook时,我总是会收到屏幕上的消息“未找到文件”,但文件在那里。。。只有当文件不存在时,任务才会失败,并显示此消息

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

-统计:
路径:/path/to/file
注册编号:st
-失败:
msg:“未找到文件”
何时:不存在圣统计

如果您想在某种情况下使播放失败,请使用:

-统计:
路径:/path/to/file
注册编号:st
-失败:
msg:“未找到文件”
何时:不存在圣统计

@KylianKlez不客气!请单击我的答案上的“接受”按钮;)@凯里安克莱兹,不客气!请单击我的答案上的“接受”按钮;)