# Possible Improvement to the 'command' Module

**URL:** <https://forum.ansible.com/t/possible-improvement-to-the-command-module/23105>\
**Category:** Ansible Project\
**Created:** [November 26, 2016, 5:22am UTC](https://forum.ansible.com/t/possible-improvement-to-the-command-module/23105 "2016-11-26T05:22:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_Forrest](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jon\_Forrest](https://forum.ansible.com/u/Jon_Forrest)\
**Post date:** [November 26, 2016, 5:22am UTC](https://forum.ansible.com/t/possible-improvement-to-the-command-module/23105/1 "2016-11-26T05:22:03Z")

</div>

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  
&nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [November 26, 2016, 4:29pm UTC](https://forum.ansible.com/t/possible-improvement-to-the-command-module/23105/2 "2016-11-26T16:29:32Z")

</div>

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  
&nbsp;&nbsp;unarchive: src=/tmp/{{ foobar\_version }}.tgz  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/usr/local  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;creates=/usr/local/{{ foobar\_version }}
