# Best practice to set up command that will run only at first session

**URL:** <https://forum.ansible.com/t/best-practice-to-set-up-command-that-will-run-only-at-first-session/15141>\
**Category:** Ansible Project\
**Created:** [May 2, 2014, 6:24am UTC](https://forum.ansible.com/t/best-practice-to-set-up-command-that-will-run-only-at-first-session/15141 "2014-05-02T06:24:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrei\_Pashkin](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Andrei\_Pashkin](https://forum.ansible.com/u/Andrei_Pashkin)\
**Post date:** [May 2, 2014, 6:24am UTC](https://forum.ansible.com/t/best-practice-to-set-up-command-that-will-run-only-at-first-session/15141/1 "2014-05-02T06:24:45Z")

</div>

What is the good way to make command run only one time and never run it again if once it succeeds?  
I think it might be done by triggering a handler which creates a flag-file after command succeds and also by defining a condition which prevents command run if that flag-file exists.  
But how to accomplish that? The problems that I can't solve here is:  
1) How to trigger a handler only if command succeeds?  
2) How to run commands only if certain file exists?

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [May 2, 2014, 1:22pm UTC](https://forum.ansible.com/t/best-practice-to-set-up-command-that-will-run-only-at-first-session/15141/2 "2014-05-02T13:22:20Z")

</div>

The command/shell modules already do this with the creates/removes options. See the documentation here:

[http://docs.ansible.com/command\_module.html](http://docs.ansible.com/command_module.html)
