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.
More on Vault, Privilege Escalation and Error Handling
What is Ansible Vault?BeginnerWhich `ansible-vault` commands do you use day to day?BeginnerHow do you supply the vault password when running a playbook?BeginnerWhat is `encrypt_string` and when is it better than encrypting a whole file?IntermediateWhat are vault IDs and why use them?AdvancedHow is Vault data encrypted and what does the file look like?Advanced