Interview Prep/Ansible/Vault, Privilege Escalation and Error Handling

What is the difference between `ignore_errors` and `failed_when`?

IntermediateConceptVault, Privilege Escalation and Error Handling
Answer

ignore_errors: true lets the play continue even though the task failed; the failure is still recorded and shown in the recap as ignored. failed_when redefines what counts as a failure based on the result, so you can ignore a known harmless exit code or fail on a text pattern.

- ansible.builtin.command: grep -q ERROR /var/log/app.log
  register: g
  failed_when: g.rc not in [0, 1]        # rc 1 = not found, fine
  changed_when: false

Prefer failed_when because ignore_errors hides real problems such as a missing binary or a bad argument, not just the one you expected.

All Ansible questions Roadmap: Ansible

More on Vault, Privilege Escalation and Error Handling