Ansible

Ansible

Made by DeepSource

Commands should not change things if nothing needs to be done ANS-E3001

Bug risk
Major

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.

Bad practice

- name: does not handle any output or return codes
  ansible.builtin.command: cat {{ myfile|quote }}

Recommended

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