But it only sets owner/group for the TLD. So recurse did not work. I tried putting it before the “state=” statement and then before the “owner” statement but it still didn’t work. Looking in /usr/share/ansible/file it doesn’t show that option in the explanations.
So, a year and a half and several releases later, still not working? It would be really nice not to have to set directory permissions in a separate step.
then the permissions and owner from “path” down were correctly set. And really, after thinking about it a bit, I wouldn’t have wanted the first step to have set everything as that would have changed the permissions and owner on the upper level directories too, which is not what I wanted. Perhaps the module needs a “chdir” argument to move to the top directory (chdir=/top/dir in my example), and then “path” can specify a relative path instead of an absolute path. That way recursive permissions can be set from that point down.
No, it worked as it should have each time. The first time I called it with the full path to the bottom leaf directory and that created all of the intermediate directories. The second time I called it I specified just the entry point to the directory tree and that change the owner and permissions of the intermediate directories from that point down to the bottom leaf.
Still, it would be more convenient if I could specify the entry point and the bottom leaf in one call instead of splitting this across two calls. And the advantage of using the “file” module each time instead of using a “shell” task is that the file task can report whether a change was made or not while a shell task will always report “changed”.
The general situation is that change detection on a tree of 5000 files would be remarkably slow. People think they want that, they do not.
AFAIK chmod/chown as shell tools do not have a return code option, settable by flag or otherwise that returns whether anything was changed. If they did, we would be able to shell out to it and you could use a “changed_when” based on the return code result.
Doing it in python with 5000 (+) stat calls would not be pretty.
AFAIK chmod/chown as shell tools do not have a return code option, settable
by flag or otherwise that returns whether anything was changed. If they
did, we would be able to shell out to it and you could use a "changed_when"
based on the return code result.
GNU chmod/chown actually *do* have something like this:
-c, --changes like verbose but report only when a change is made
If you combine this with '-R' and '-f' (for silent), then if there is anything
in stdout at all, you know a change has been made.
I've been using it like so while waiting for the aforementioned pull
request:
Not ideal, in my opinion, but it works and could perhaps be used in
set_mode_if_different() method in the AnsibleModule class. Not sure how
to deal with check mode using that method, though.
So the idea of backing it by chmod with -c sounds great but we’d need an option for when it was non-GNU, really it would need to autodetect and use the legacy path.
Generally I don’t like including alternate code paths, but this would mainly be for recursive=yes and in that case we could have a caveat about behavior on non-GNU systems if need be.