首先,需要检查在哪个任务中出现了此错误,并尝试找出导致此错误的条件。其次,可以通过在条件语句中使用括号、引号和变量来确保条件正确。示例代码:
name: Check if file exists stat: path: /path/to/file.txt register: file_stat
name: Run command if file exists command: /path/to/script.sh when: file_stat.stat.exists == true
在上面的示例中,如果文件存在,则运行脚本。在条件“when:”中使用了变量“file_stat.stat.exists”来检查文件是否存在。如果变量不正确,则会出现条件检查失败的错误。
上一篇:Ansible条件检查失败
下一篇:Ansible条件任务处理