Copy a file with Ansible if it doesn’t exist

Assuming index.php exists in the role’s files subdirectory:

- copy: 
    src: index.php 
    dest: /var/www/index.php 
    force: no

The decisive property is force. As the documentation explains, the default is yes, which will replace the remote file when contents are different than the source. If no, the file will only be transferred if the destination does not exist.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)