Excerpts from Michael DeHaan's message of 2014-07-30 07:51:22 -0400:
> 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.
Just though I'd point out that there is a pull request for this:
https://github.com/ansible/ansible/pull/5220
Slow may very well be a concern, though.
> 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:
- command: chmod -cfR u+X,g+X,o-w,o+X "{{ my_dir }}"
register: perm_change
changed_when: perm_change.stdout
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.
--
Morgan Hamill