# BUG:  This is some weird stuff.  Copy module changing file

**URL:** <https://forum.ansible.com/t/bug-this-is-some-weird-stuff-copy-module-changing-file/25885>\
**Category:** Ansible Project\
**Created:** [November 1, 2017, 3:34pm UTC](https://forum.ansible.com/t/bug-this-is-some-weird-stuff-copy-module-changing-file/25885 "2017-11-01T15:34:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [November 1, 2017, 3:34pm UTC](https://forum.ansible.com/t/bug-this-is-some-weird-stuff-copy-module-changing-file/25885/1 "2017-11-01T15:34:54Z")

</div>

# rpm -q ansible

ansible-2.4.1.0-1.el7.ans.noarch

I was having problems after running one of my playbooks with an unknown module. I narrowed it down to a task in my playbook. Can someone explain this? Seems like a bug.

`

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [November 1, 2017, 3:56pm UTC](https://forum.ansible.com/t/bug-this-is-some-weird-stuff-copy-module-changing-file/25885/2 "2017-11-01T15:56:37Z")

</div>

I filed a bug:

[https://github.com/ansible/ansible/issues/32445](https://github.com/ansible/ansible/issues/32445)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 1, 2017, 3:59pm UTC](https://forum.ansible.com/t/bug-this-is-some-weird-stuff-copy-module-changing-file/25885/3 "2017-11-01T15:59:11Z")

</div>

force: no prevents a copy if the dest file exists

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [November 1, 2017, 4:00pm UTC](https://forum.ansible.com/t/bug-this-is-some-weird-stuff-copy-module-changing-file/25885/4 "2017-11-01T16:00:42Z")

</div>

Yes, but the contents of the file change… the force option is set that way on purpose so I don’t overwrite any local changes if they exist.

---

<div class="post-metadata">

**Author:** ![tkuratom](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@tkuratom](https://forum.ansible.com/u/tkuratom)\
**Post date:** [November 1, 2017, 6:39pm UTC](https://forum.ansible.com/t/bug-this-is-some-weird-stuff-copy-module-changing-file/25885/5 "2017-11-01T18:39:10Z")

</div>

Ansible is stateless. So it doesn't know if the remote file exists in  
the way you have it because you changed it on the remote system or  
because a previous ansible run dropped that version of hte file there.  
If you want Ansible to ensure that the remote file matches what you  
have at your source then you must have force: yes. If you want  
ansible to always respect remote changes then you have force: no.

You can come up with your own method to track remote state to  
determine whether to overwrite the file or not (by taking a hash of  
previous files pushed out by ansible and saving it somewhere for  
comparison in the future) you certainly can write several tasks to  
take care of that but that is outside of the scope of what's built  
into Ansible.

-Toshio

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [November 1, 2017, 7:40pm UTC](https://forum.ansible.com/t/bug-this-is-some-weird-stuff-copy-module-changing-file/25885/6 "2017-11-01T19:40:19Z")

</div>

I set force to yes, and it is still happening.

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [November 1, 2017, 7:45pm UTC](https://forum.ansible.com/t/bug-this-is-some-weird-stuff-copy-module-changing-file/25885/7 "2017-11-01T19:45:27Z")

</div>

OK, I see it is grabbing the file from my ansible server, and copying it to the managed server. I was expecting it to copy it from the managed server to the managed server… now I just need to figure out the right syntax for that.

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [November 1, 2017, 7:47pm UTC](https://forum.ansible.com/t/bug-this-is-some-weird-stuff-copy-module-changing-file/25885/8 "2017-11-01T19:47:23Z")

</div>

Done, the key is to add:

```auto
remote_src: yes

```
