詳細的具體方案見 https://stackoverflow.com/questions/35654286/how-to-check-if-a-file-exists-in-ansible
這裏舉出其中最具代表性的例子
- name: Register file
stat:
path: "/tmp/test_file"
register: file_path
- name: Create file if it doesn't exists
file:
path: "/tmp/test_file"
state: touch
when: file_path.stat.exists == False