# set file permission ONLY if file exists?

**URL:** <https://forum.ansible.com/t/set-file-permission-only-if-file-exists/19782>\
**Category:** Ansible Project\
**Created:** [November 17, 2015, 12:34pm UTC](https://forum.ansible.com/t/set-file-permission-only-if-file-exists/19782 "2015-11-17T12:34:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorgen\_Hagg](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@Jorgen\_Hagg](https://forum.ansible.com/u/Jorgen_Hagg)\
**Post date:** [November 17, 2015, 12:34pm UTC](https://forum.ansible.com/t/set-file-permission-only-if-file-exists/19782/1 "2015-11-17T12:34:46Z")

</div>

I’m trying to use the file module to set permissions on files that exists.  
The manual says that state=file will do so, but I still get an error, “is absent, cannot continue”.

From the manual for state: “If `file`, the file will NOT be created if it does not exist”

Is this how it is supposed to work?

ansible 1.9.4, debian sid

file: path={{item}} mode=0664 owner=xxx group=yyy state=file  
with\_items:

- logfile1
- logfile2 …

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 17, 2015, 10:58pm UTC](https://forum.ansible.com/t/set-file-permission-only-if-file-exists/19782/2 "2015-11-17T22:58:28Z")

</div>

the error is correct the file does not exist and the permissions  
cannot be updated

ignore\_errors: yes will allow for it to keep running even if the file  
does not exist, another option is using the stat: module to check if  
the file exists and run file: conditionally on that.
