`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.
More on Modules, Idempotency and Handlers
`ERROR! The requested handler 'Restart nginx' was not found in either the main handlers list nor in the listening handlers list`BeginnerA handler named `restart {{ app_service }}` is never found when notified as `restart myapp`AdvancedA `command` task reports `changed` on every run, and the Molecule idempotence check failsBeginner`curl ... | tar xz` fails on the host but the `shell` task reports successIntermediate`lineinfile` appends the same line again on every runIntermediate`lineinfile` with `backrefs: true` reports `ok` but the line was never addedIntermediate