# file module - state=touch always finishes as changed

**URL:** <https://forum.ansible.com/t/file-module-state-touch-always-finishes-as-changed/20086>\
**Category:** Ansible Project\
**Created:** [December 29, 2015, 3:27am UTC](https://forum.ansible.com/t/file-module-state-touch-always-finishes-as-changed/20086 "2015-12-29T03:27:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Koji\_Tanaka](https://avatars.discourse-cdn.com/v4/letter/k/a698b9/32.png) [@Koji\_Tanaka](https://forum.ansible.com/u/Koji_Tanaka)\
**Post date:** [December 29, 2015, 3:27am UTC](https://forum.ansible.com/t/file-module-state-touch-always-finishes-as-changed/20086/1 "2015-12-29T03:27:01Z")

</div>

Hello Ansible Community,

I'd like to create a task which ensures a file exists(if a file  
doesn't exist, it should create an empty file). Now I use file  
module's state=touch, but it always finishes as changed. Is there a  
way to prevent it from touching when file exists?

Best regards,  
Koji

---

<div class="post-metadata">

**Author:** ![Koji\_Tanaka](https://avatars.discourse-cdn.com/v4/letter/k/a698b9/32.png) [@Koji\_Tanaka](https://forum.ansible.com/u/Koji_Tanaka)\
**Post date:** [December 29, 2015, 3:33am UTC](https://forum.ansible.com/t/file-module-state-touch-always-finishes-as-changed/20086/2 "2015-12-29T03:33:45Z")

</div>

RESOLVED. I found that adding "changed\_when: False" does the trick, as  
suggested on this issue.  
[https://github.com/ansible/ansible-modules-core/issues/170](https://github.com/ansible/ansible-modules-core/issues/170)

Thank you,  
Koji

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 29, 2015, 3:48am UTC](https://forum.ansible.com/t/file-module-state-touch-always-finishes-as-changed/20086/3 "2015-12-29T03:48:48Z")

</div>

I actually tend to use the copy module, like so:

- copy: content=“” dest=/path/to/file force=no

force=no keeps it from replacing the file when it exists and the content is different.

[http://docs.ansible.com/ansible/copy\_module.html](http://docs.ansible.com/ansible/copy_module.html)
