Ansible tasks should be idempotent. Eg. if the task does not modify anything, it should return
ok instead of
changed. Most builtin modules and tasks are already, but for tasks such as
shell you need to help ansible a bit.
For a task that does purely checking and does not modify anything, you should add:
The latter allows the task to run even in check mode.
For the sake of completeness, such tasks are usually combined with another that does the actual modification, eg:
- command: check command that returns true when no change needed
- command: modify command
when: result.rc != 0