Interview Prep/Ansible/Modules, Idempotency and Handlers

`failed_when` with two conditions never fails although `stderr` contains `ERROR`

IntermediateTroubleshootingModules, Idempotency and Handlers
Answer

Likely causes → A list under failed_when is combined with AND. All items must be true for the task to fail.

failed_when:
  - result.rc != 0
  - "'ERROR' in result.stderr"      # both must be true

Fix → Use or explicitly:

failed_when: result.rc != 0 or 'ERROR' in result.stderr

Prevent → Write mixed conditions on one line with clear and/or and parentheses. Add a Molecule case that forces the failure.

All Ansible questions Roadmap: Ansible

More on Modules, Idempotency and Handlers