# Limitations of the file module

**URL:** <https://forum.ansible.com/t/limitations-of-the-file-module/13465>\
**Category:** Ansible Project\
**Created:** [September 12, 2013, 6:35pm UTC](https://forum.ansible.com/t/limitations-of-the-file-module/13465 "2013-09-12T18:35:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nils\_Pascal\_Illensee](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Nils\_Pascal\_Illensee](https://forum.ansible.com/u/Nils_Pascal_Illensee)\
**Post date:** [September 12, 2013, 6:35pm UTC](https://forum.ansible.com/t/limitations-of-the-file-module/13465/1 "2013-09-12T18:35:54Z")

</div>

Hi,

right now the file module does not create files, if they do not exist. But in contrast to that it creates directories, if they do not exist. I personally think this is inconsistent.

And there are good reasons to create files, if they do not exist, e.g. for syslogd on FreeBSD, if you want to use /var/log/console.log for console.info, you have to create that file and it needs certain file permissions (mode ‘600’). Right now you have to use the copy module to create the file without content, with correct permissions and force=no, so you won’t delete content in subsequent playbook runs. If you want to ensure correct file permission in subsequent playbook runs, you have to additionally use the file module. In comparison Puppet handles this with just one declaration.

The file module could handle the whole situation alone, if it would create files. Maybe a parameter ‘create’ could be added, so you could decide whether you want this behavior or not.

Regards,  
Nils

p.s. beside this little issue I really like Ansible a lot 🙂

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 12, 2013, 6:39pm UTC](https://forum.ansible.com/t/limitations-of-the-file-module/13465/2 "2013-09-12T18:39:12Z")

</div>

Could you open a github issue for this? Thanks!

---

<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:** [September 12, 2013, 6:45pm UTC](https://forum.ansible.com/t/limitations-of-the-file-module/13465/3 "2013-09-12T18:45:42Z")

</div>

It should be easy to make “file: path=/tofile state=present” the equivalent of “touch /tofile”, I’ll put it on my queue unless someone beats me to it.

---

<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:** [September 12, 2013, 7:56pm UTC](https://forum.ansible.com/t/limitations-of-the-file-module/13465/4 "2013-09-12T19:56:43Z")

</div>

You can already get this behavior by using the copy module with “force=no” and either a blank file as source or content=no.

But I would support there being a state=touch

I would not support having state=present make the file present as I think it’s useful to have it error out when the file is not there in many cases and would be a bit hesitant to break compatibility.

---

<div class="post-metadata">

**Author:** ![Nils\_Pascal\_Illensee](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Nils\_Pascal\_Illensee](https://forum.ansible.com/u/Nils_Pascal_Illensee)\
**Post date:** [September 12, 2013, 8:18pm UTC](https://forum.ansible.com/t/limitations-of-the-file-module/13465/5 "2013-09-12T20:18:31Z")

</div>

I added an issue on github ([https://github.com/ansible/ansible/issues/4097](https://github.com/ansible/ansible/issues/4097)) and really like to have state=(touch|present) or equivalent.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 12, 2013, 8:27pm UTC](https://forum.ansible.com/t/limitations-of-the-file-module/13465/6 "2013-09-12T20:27:52Z")

</div>

I agree with mdehaan and prefer state=touch, it makes it more clear about what it does. In the event that the file exists, we could also have it replicate what touch does via the python os library using os.utime().

---

<div class="post-metadata">

**Author:** ![Nils\_Pascal\_Illensee](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Nils\_Pascal\_Illensee](https://forum.ansible.com/u/Nils_Pascal_Illensee)\
**Post date:** [September 12, 2013, 9:35pm UTC](https://forum.ansible.com/t/limitations-of-the-file-module/13465/7 "2013-09-12T21:35:22Z")

</div>

I updated the github issue to add state=touch.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 22, 2013, 2:22pm UTC](https://forum.ansible.com/t/limitations-of-the-file-module/13465/8 "2013-09-22T14:22:11Z")

</div>

The above was just merged in, thanks to René Moser (@resmo) for submitting it!
