chown recursively with file module is very slow

1,105 views
Skip to first unread message

Thomas Steinbach

unread,
Dec 2, 2015, 1:26:17 PM12/2/15
to Ansible Project
Hi, I want to ensure that a directory and all its children belongs to a user/group. Normally I would do following with Ansible:

file:
 dest
: /path/to/dir
 owner
: userx
 
group: groupx
 recurse
: yes


However this approach takes in my case about 10 minutes or more, because the folder contains recursively hundreds of subfolders and thousands of files. With the following approach this task takes me just seconds:

command: "chown -R userx:groupx /path/to/dir"
changed_when
: false


Why is the Ansible native approach so much slower? Is it because it checks the state before/after the (possible) change? Or is there a faster good practice approach with Ansible?

Brian Coca

unread,
Dec 2, 2015, 1:29:49 PM12/2/15
to Ansible Project
that is exactly it, ansible checks each and every file/dir in the
tree, 'chown -R ' does not, it just sets it.

--
Brian Coca
Reply all
Reply to author
Forward
0 new messages