# Maintain file timestamp during copy

**URL:** <https://forum.ansible.com/t/maintain-file-timestamp-during-copy/12526>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [March 18, 2013, 8:37pm UTC](https://forum.ansible.com/t/maintain-file-timestamp-during-copy/12526 "2013-03-18T20:37:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [March 18, 2013, 8:37pm UTC](https://forum.ansible.com/t/maintain-file-timestamp-during-copy/12526/1 "2013-03-18T20:37:58Z")

</div>

This seems to be a dangerous idea, as it would cover up the last  
modified time of the file.

You should just check to see that the file md5sums are the same.

Ansible will already not transfer the file if it does not need to be replaced.

---

<div class="post-metadata">

**Author:** ![VK1](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@VK1](https://forum.ansible.com/u/VK1)\
**Post date:** [March 19, 2013, 4:28am UTC](https://forum.ansible.com/t/maintain-file-timestamp-during-copy/12526/2 "2013-03-19T04:28:58Z")

</div>

IMHO this is standard sysadmin practice, via "cp -p" or "scp -p ..." or "rsync -a..." and so on. It doesn't seem unreasonable to expect a similar capability in ansible.

-VK

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [March 19, 2013, 4:41am UTC](https://forum.ansible.com/t/maintain-file-timestamp-during-copy/12526/3 "2013-03-19T04:41:37Z")

</div>

Unless I am reading the docs wrong, rsync -t (part of -a) preserves  
timestamps of \*\*unchanged\*\* files.

scp -p is something I don't use, and it's the first time I've received  
this request. Not to say "new requests are bad", but "thousands of  
users and not received this request" is at least significant 🙂

My logic was this -- if someone had manually edited it, and then the  
file is edited from the config system, you'd lose that record, which  
means the user might be rather confused.

Conversation to the contrary is welcome, of course, though I think the  
role of a config & deployment system is not the same as the role of  
low level shell tools.

I'd also be curious if anyone else agrees with me.

I'm willing to accept this, but I want to understand the underlying  
reason for this first.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [March 19, 2013, 4:42am UTC](https://forum.ansible.com/t/maintain-file-timestamp-during-copy/12526/4 "2013-03-19T04:42:19Z")

</div>

(To clarify, I'm willing to accept this as something like a global  
option, but not the default, and not as a per template or copy  
parameter)
