0
我想验证文件路径如果文件存在与否。我写下了下面的任务。Ansible Display自定义错误消息“stat”
- name: File Validation
stat: path={{src_file_path}}{{filename}} get_md5=yes
register: file
- fail: msg="Whoops! File does not exist.!"
when: file.stat.exists == False
“失败”模块抛出下面的错误
TASK: [deploy-stack | fail msg="Whoops! File does not exist.!"] ***************
failed: [192.168.36.128] => {"failed": true}
msg: Whoops! File does not exist.!
FATAL: all hosts have already failed -- aborting
我没有得到为什么失败模块是表现为它想。
谢谢Chandan,我想验证本地主机上的文件。如果文件存在,我会将它复制到远程服务器并验证校验和。 在这种情况下,如果文件路径改变,我无法处理异常。 ansible正在“跳过”验证和文件复制任务。 – tgcloud
你可以简单地添加另一个条件,当它不存在时做任何你想做的事情,这样它就不会被跳过 - 更新了答案。 –