# Ensuring a command only runs once

**URL:** <https://forum.ansible.com/t/ensuring-a-command-only-runs-once/13258>\
**Category:** Ansible Project\
**Created:** [August 6, 2013, 12:46am UTC](https://forum.ansible.com/t/ensuring-a-command-only-runs-once/13258 "2013-08-06T00:46:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Rowlands](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@Jonathan\_Rowlands](https://forum.ansible.com/u/Jonathan_Rowlands)\
**Post date:** [August 6, 2013, 12:46am UTC](https://forum.ansible.com/t/ensuring-a-command-only-runs-once/13258/1 "2013-08-06T00:46:24Z")

</div>

Sorry if this has been asked before… Is there a pattern to ensure a command gets run once and only once on a machine? For instance if I want to seed a database on the initial deploy but I would never want to run this command again. I have been doing the following:  
shell: mycommand && touch somefile creates=somefile

It works but wasn’t sure if there was a better way.

Thanks,  
Jon

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 6, 2013, 1:07am UTC](https://forum.ansible.com/t/ensuring-a-command-only-runs-once/13258/2 "2013-08-06T01:07:36Z")

</div>

Creates is the way to go here!

---

<div class="post-metadata">

**Author:** ![Jonathan\_Rowlands](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@Jonathan\_Rowlands](https://forum.ansible.com/u/Jonathan_Rowlands)\
**Post date:** [August 6, 2013, 1:09am UTC](https://forum.ansible.com/t/ensuring-a-command-only-runs-once/13258/3 "2013-08-06T01:09:21Z")

</div>

Cool, thanks!

---

<div class="post-metadata">

**Author:** ![Stefan\_Eriksson](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Stefan\_Eriksson](https://forum.ansible.com/u/Stefan_Eriksson)\
**Post date:** [April 9, 2014, 4:23pm UTC](https://forum.ansible.com/t/ensuring-a-command-only-runs-once/13258/4 "2014-04-09T16:23:49Z")

</div>

hi I have this exact issue but dont understand the anwer “Creates is the way to go here!” could anyone explain in little more detail? thanks.

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [April 10, 2014, 5:54pm UTC](https://forum.ansible.com/t/ensuring-a-command-only-runs-once/13258/5 "2014-04-10T17:54:26Z")

</div>

[http://docs.ansible.com/shell\_module.html](http://docs.ansible.com/shell_module.html)

parameter required default choices comments

creates no   
&nbsp;&nbsp;&nbsp;&nbsp;a filename, when it already exists, this step will \*not\* be run.
