Possible Improvement to the 'command' Module

The Ansible documentation shows the following example for the 'command'
module"

- command: /usr/bin/make_database.sh arg1 arg2 creates=/path/to/database

The idea here is that if the /path/to/database file already exists,
the command doesn't run. This is a poor man's way of adding idempotence.

But, what if a previous module, or external command, created a new
version of /path/to/database that requires the command to be run again?
The mere fact that /path/to/database exists isn't sufficient to
determine with the command should be run again. Instead, it's the
combination of whether the file exists, and its contents.

What if there were an addition argument called "with_sha1hash" that
contains a hash value to use to recognize whether /path/to/database has
changed. For example,

- command: /usr/bin/make_database.sh arg1 arg2 creates=/path/to/database
  with_sha1hash="ab34ac"

(The hash value can be enough of the first characters of the hash to
be unique, the way Git does things).

If /path/to/database exists, but it doesn't have "ab34ac" as
its sha1 hash, the command would be run.

This would be an optional argument so it wouldn't affect
any existing playbooks.

I have to admit I don't have any examples of when this would be
necessary but it seems like such a thing could exist. Does this
make sense?

Jon Forrest

It's not a bad idea, but it would need a bit of work to cater to
things like directories.
I often use a task like this to create automatically versioned
directory names if I can't
find an RPM:

- name: extract {{ foobar_version }}.tgz
  unarchive: src=/tmp/{{ foobar_version }}.tgz
                    dest=/usr/local
                    creates=/usr/local/{{ foobar_version }}