Tasks should tell Ansible when to return changed
, unless the task only reads information. To do this, set changed_when
, use the creates
or removes
argument, or use when
to run the task only if another check has a particular result.
- name: does not handle any output or return codes
ansible.builtin.command: cat {{ myfile|quote }}
This snippet uses the output and the return code of the command.
- name: handle shell output with return code
ansible.builtin.shell: cat {{ myfile|quote }}
register: myoutput
changed_when: myoutput.rc != 0