我想在ansible中检查一个文件是否存在。
用于检查单个文件的代码,完美运行。
- hosts: all
tasks:
- name: Ansible check file exists example.
stat:
path: /Users/data/info.text
register: file_details
- debug:
msg: "The file exists"
when: file_details.stat.exists
我想要检查 /Users/data/info.text 或 /Users/data/info.html 是否存在,我尝试使用或运算符,但它提示 yml 文件无效。
- hosts: all
tasks:
- name: Ansible check file exists example.
stat:
path: /Users/data/info.text or /Users/data/info.html
register: file_details
- debug:
msg: "The file exists"
when: file_details.stat.exists