# Lossless file command ?

**URL:** <https://forum.ansible.com/t/lossless-file-command/15466>\
**Category:** Ansible Project\
**Created:** [June 15, 2014, 8:50pm UTC](https://forum.ansible.com/t/lossless-file-command/15466 "2014-06-15T20:50:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laurent\_PETIT](https://avatars.discourse-cdn.com/v4/letter/l/8c91f0/32.png) [@Laurent\_PETIT](https://forum.ansible.com/u/Laurent_PETIT)\
**Post date:** [June 15, 2014, 8:50pm UTC](https://forum.ansible.com/t/lossless-file-command/15466/1 "2014-06-15T20:50:28Z")

</div>

Hello,

Is there an alternate to the file command that would prevent overriding a file on a server (and then fail) if it detects that the file has been manually changed since the last play?

This could be helpful in a mixed environment where some people still have access to the server and may change some configuration without remembering to do the changes in Ansible config files.

I since that at least palletops has this feature, I guess it is doing so by keeping a hash somewhere on the server.

Regards,

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 16, 2014, 1:24am UTC](https://forum.ansible.com/t/lossless-file-command/15466/2 "2014-06-16T01:24:13Z")

</div>

The file command doesn’t replace contents of files.

If you are thinking of copy, that parameter is force=no.

---

<div class="post-metadata">

**Author:** ![Laurent\_PETIT](https://avatars.discourse-cdn.com/v4/letter/l/8c91f0/32.png) [@Laurent\_PETIT](https://forum.ansible.com/u/Laurent_PETIT)\
**Post date:** [June 16, 2014, 5:37am UTC](https://forum.ansible.com/t/lossless-file-command/15466/3 "2014-06-16T05:37:53Z")

</div>

Yes, I meant the copy command.

Does the force flag detect whether the remote file has been modified externally ? I thought it was just a flag working in a binary way: copy the file the first time, and do not copy again if present (with no check on the content). Which is not the behavior I was describing.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [June 16, 2014, 3:14pm UTC](https://forum.ansible.com/t/lossless-file-command/15466/4 "2014-06-16T15:14:18Z")

</div>

I use xattr command to keep md5sum of the files I copy, then compare it on  
the current file, this lets me detect when it was changed externally.

---

<div class="post-metadata">

**Author:** ![Laurent\_PETIT](https://avatars.discourse-cdn.com/v4/letter/l/8c91f0/32.png) [@Laurent\_PETIT](https://forum.ansible.com/u/Laurent_PETIT)\
**Post date:** [June 16, 2014, 8:03pm UTC](https://forum.ansible.com/t/lossless-file-command/15466/5 "2014-06-16T20:03:32Z")

</div>

Thanks for the answer Brian.

So there’s no built-in support. I can live with that, just wanted to check I hadn’t overlooked the obvious.

Cheers

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 17, 2014, 7:03pm UTC](https://forum.ansible.com/t/lossless-file-command/15466/6 "2014-06-17T19:03:32Z")

</div>

The copy command does use the md5sum utility when possible to minimize copying.

This is not always possible under sudo.
