How check a file exists in ansible?
问题 I have to check whether a file exists in /etc/ . If the file exists then I have to skip the task. Here is the code I am using: - name: checking the file exists command: touch file.txt when: $(! -s /etc/file.txt) If the file.txt exists then I have to skip the task. 回答1: You can first check that the destination file exists or not and then make a decision based on the output of it's result. tasks: - name: Check that the somefile.conf exists stat: path: /etc/file.txt register: stat_result - name: