# File module - would be great to be able to apply attribs to just files or dirs

**URL:** <https://forum.ansible.com/t/file-module-would-be-great-to-be-able-to-apply-attribs-to-just-files-or-dirs/15195>\
**Category:** Ansible Project\
**Created:** [May 8, 2014, 12:45am UTC](https://forum.ansible.com/t/file-module-would-be-great-to-be-able-to-apply-attribs-to-just-files-or-dirs/15195 "2014-05-08T00:45:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eduardr](https://avatars.discourse-cdn.com/v4/letter/e/a8b319/32.png) [@eduardr](https://forum.ansible.com/u/eduardr)\
**Post date:** [May 8, 2014, 12:45am UTC](https://forum.ansible.com/t/file-module-would-be-great-to-be-able-to-apply-attribs-to-just-files-or-dirs/15195/1 "2014-05-08T00:45:15Z")

</div>

Hello,

I haven’t found a way to recursively apply attributes (user/group/mode) to just  
files or just directories in a recursive way. A common use case is wanting a  
directory structure to be 0755 and files 0644 - there appears to way to do that  
currently using a module. Only command or shell chmod -R would work in this  
case it seems.

Regards,  
–Ed

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 9, 2014, 11:57pm UTC](https://forum.ansible.com/t/file-module-would-be-great-to-be-able-to-apply-attribs-to-just-files-or-dirs/15195/2 "2014-05-09T23:57:33Z")

</div>

The pattern is to just shell out to chmod/chown since the changed detection and reporting of changes would be squirrely.

People think you can just chmod every directory along the line but you can’t, the rules along the way might need to be different at different levels, which is why this is not recursive.

---

<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:** [May 10, 2014, 3:08am UTC](https://forum.ansible.com/t/file-module-would-be-great-to-be-able-to-apply-attribs-to-just-files-or-dirs/15195/3 "2014-05-10T03:08:49Z")

</div>

If you REAAAAAAALLLLY need it, I suggest 2 tasks, the first finds the directories you want to change:

- shell: find /path -type d -owner -etc  
register: dirs\_to\_change

- file: path={{item}} owner=“correct one” …  
with\_items: dirs\_to\_change.stdout\_lines

or something similar.  
​
