What is the significance of an Ansible task reporting that something has changed?

I have a task that checks if my process is listening on port 8080 and only when the exit code is not zero, would I run fail with a message.

When the service is running, it reports that the status has changed. I want it to say ok. What does a changed status actually mean in Ansible ?


Anything that is dependent on something on the target will get the status "changed" when executed, even if it's just a shell command to echo something.

To suppress the "changed" status, you can add the following line to the task:

changed_when: false

This and other relevant things are listed on the Ansible doc page for error handling in playbooks.


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 command and shell you need to help ansible a bit.

For a task that does purely checking and does not modify anything, you should add:

changed_when: False
always_run: yes

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
  register: result
  changed_when: False
  always_run: yes
- command: modify command
  when: result.rc != 0