Copy Local File If Exists, Using Ansible
Answer : A more comprehensive answer: If you want to check the existence of a local file before performing some task, here is the comprehensive snippet: - name: get file stat to be able to perform a check in the following task local_action: stat path=/path/to/file register: file - name: copy file if it exists copy: src=/path/to/file dest=/destination/path when: file.stat.exists If you want to check the existence of a remote file before performing some task, this is the way to go: - name: get file stat to be able to perform check in the following task stat: path=/path/to/file register: file - name: copy file if it exists copy: src=/path/to/file dest=/destination/path when: file.stat.exists Change your first step into the following on - name: copy local filetocopy.zip to remote if exists local_action: stat path="../filetocopy.zip" register: result If you don't wont to set up two tasks, you could use 'is file' to check if local files exist...