copy module: fail if remote file exists and is different from source?

Hi,

is there an (easy) way to make the copy module [1] fail if the remote
file exists and is different from the source file?
The goal is to
- not override the destination (force=no) and
- abort if the file exists and is different from the source.

The fetch module [2] has a 'fail_on_missing' parameter. I would need a
fail_on_remotefileexists_but_different :wink:
Currently one is left with
- backup=yes
or
- force=no
but both parameter won't help for the specific use-case.

Anyone else had this use-case yet and made a workaround?

thanks,
nusenu

[1] https://docs.ansible.com/ansible/copy_module.html
[2] https://docs.ansible.com/ansible/fetch_module.html

is there an (easy) way to make the copy module [1] fail if the remote
file exists and is different from the source file?
The goal is to
- not override the destination (force=no) and
- abort if the file exists and is different from the source.

The fetch module [2] has a 'fail_on_missing' parameter. I would need a
fail_on_remotefileexists_but_different :wink:
Currently one is left with
- backup=yes
or
- force=no
but both parameter won't help for the specific use-case.

Anyone else had this use-case yet and made a workaround?

My workaround procedure is [1]:

1) copy with force=no
2) fetch
3) compare files locally via shell (sha1sum)
4) fail if fingerprints do not match

If there is a less dirty solution let me know :wink:

[1]
https://github.com/nusenu/ansible-relayor/commit/b2462b6b8b4ed3b1351ff167c6dd5f7ed3263e7a

you could just use stat module to check the file remotely (you would
also get hash to compare to local file)