ansible/ansible — pull request #6029 by b6d (2014-02-16 15:13:14+00:00)
Title: Proposal for a new parameter to the command module ("maybe_changes")

I find myself writing more and more playbooks in which I use the following sequence of tasks to notify a handler in case a call to a command (`smbpasswd` for example) changes some file (`secrets.tdb` in this example):

- a `command`-task calling `md5sum` for the file with `changed_when=false` and `register=state_before`
- a `command`-task to actually do the work (`smbpasswd` here) with `changed_when=false`
- a `command`-task calling `md5sum` for a second time with `register=state_after`, `changed_when="state_before != state_after"` and `notify=some_handler`

It is clear to me that it is practically impossible to determine reliably whether a `command`-task changed something. But I think there are use cases, where it makes sense to check if the task only changed a particular file. For these cases I'd like to propose a new parameter for the command module to specify the file one expects to change.

I've tried to make a sample implementation of this (the new parameter is called `maybe_changes` in it) which I'd like to leave here for your consideration/comments.