# Copy Module doesnt override destination file

**URL:** <https://forum.ansible.com/t/copy-module-doesnt-override-destination-file/22235>\
**Category:** Ansible Project\
**Created:** [August 8, 2016, 4:56pm UTC](https://forum.ansible.com/t/copy-module-doesnt-override-destination-file/22235 "2016-08-08T16:56:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anushri\_Mishra](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@Anushri\_Mishra](https://forum.ansible.com/u/Anushri_Mishra)\
**Post date:** [August 8, 2016, 4:56pm UTC](https://forum.ansible.com/t/copy-module-doesnt-override-destination-file/22235/1 "2016-08-08T16:56:44Z")

</div>

hi,

so this is what I have in my yml file:

- name: Copy War File

copy: src=externaluserwebapi.war dest=/usr/share/tomcat7/webapps

become: True

become\_method: sudo

and this is what I get when I run playbook:

ok: [10.1.33.227] =\> {“changed”: false, “checksum”: “c93572d33bd0555a87341380ac389382c225a92d”, “dest”: “/usr/share/tomcat7/webapps/externaluserwebapi.war”, “gid”: 0, “group”: “root”, “invocation”: {“module\_args”: {“backup”: false, “content”: null, “delimiter”: null, “dest”: “/usr/share/tomcat7/webapps/externaluserwebapi.war”, “directory\_mode”: null, “follow”: false, “force”: true, “group”: null, “mode”: null, “original\_basename”: “externaluserwebapi.war”, “owner”: null, “regexp”: null, “remote\_src”: null, “selevel”: null, “serole”: null, “setype”: null, “seuser”: null, “src”: “/home/ec2-user/.ansible/tmp/ansible-tmp-1470673998.42-22221732776252/source”, “validate”: null}}, “md5sum”: “ba5224fb84a5f82d5fa7b8a8f83c4b2e”, “mode”: “0644”, “owner”: “root”, “size”: 17027813, “src”: “/home/ec2-user/.ansible/tmp/ansible-tmp-1470673998.42-22221732776252/source”, “state”: “file”, “uid”: 0}

Not sure why but copy module is not overriding the script in destination directory.I read that by default it is force=yes.Please help.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 8, 2016, 11:08pm UTC](https://forum.ansible.com/t/copy-module-doesnt-override-destination-file/22235/2 "2016-08-08T23:08:26Z")

</div>

The reason is because the files is identical.

To debug you could add this tasks.

Add this two task before "Copy War File"  
- stat:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path=externaluserwebapi.war  
&nbsp;&nbsp;&nbsp;delegate\_to: localhost  
&nbsp;&nbsp;&nbsp;register: result

- debug: var=result

and add this two task after "Copy War File"  
- stat:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path=/usr/share/tomcat7/webapps  
&nbsp;&nbsp;&nbsp;register: result

- debug: var=result

---

<div class="post-metadata">

**Author:** ![Anushri\_Mishra](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@Anushri\_Mishra](https://forum.ansible.com/u/Anushri_Mishra)\
**Post date:** [August 9, 2016, 9:34pm UTC](https://forum.ansible.com/t/copy-module-doesnt-override-destination-file/22235/3 "2016-08-09T21:34:10Z")

</div>

Thanks Kai.Yes,the files are identical.But there should be some way to overwrite it.Is there any way?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 9, 2016, 9:56pm UTC](https://forum.ansible.com/t/copy-module-doesnt-override-destination-file/22235/4 "2016-08-09T21:56:03Z")

</div>

No, this is part of Ansibles idempontecy[1], it does not do any changes if the files is identical.  
Why do you want to overwrite the file if it's identical, overwrite it will have no function since nothing will change.

[1] [https://docs.ansible.com/ansible/glossary.html#term-idempotency](https://docs.ansible.com/ansible/glossary.html#term-idempotency)

---

<div class="post-metadata">

**Author:** ![Anushri\_Mishra](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@Anushri\_Mishra](https://forum.ansible.com/u/Anushri_Mishra)\
**Post date:** [August 9, 2016, 10:07pm UTC](https://forum.ansible.com/t/copy-module-doesnt-override-destination-file/22235/5 "2016-08-09T22:07:27Z")

</div>

k got it.thx.
