Idempotent operations in Ansible ?

Hi I’m new to Ansible so it might looks like a very basic question. I’ve read that Ansible is idempotent.

My question is related to how Ansbile handles operations invoked using the shell or command module.

Here is an example. For example I’ve a long running shell script that I invoked on the remote host using Ansible.
Now if I run the playbook multiple times will Ansible try to run the script again if it’s already running?
If not how does it know that the “specific script is already running” ?

In another variation of this scenario, what if I really want to run multiple versions of the same process on the remote host. How does Ansible handle that?

Thanks

There are several ways as documented in the command module.

You can set “creates= and removes=” operations (see module docs)

You can also use the “when:” statement to conditionally decide to run things

If the command itself is already idempotent (many things are) you can also use “changed_when:” to control whether it reports change.