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

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?

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

http://docs.ansible.com/command_module.html