This sequence fails (as expected), because the “bla” line is not in the file. If I enter a string, which is in the file, it doesn’t fail. So far so good.
Now I wanted to examine several lines, but this never fails. “line1” to “line4” are in, “bla” not.
But the result is OK…
If it never fails is just because you are iterating over items and registering the result of each iteration. So the condition is only evaluated only on the last iteration.
No, the reason was the wrong “{{ item.item }}” reference.
Real world example:
name: TEST - Check /tmp/out.log for some lines expected to be there
tags: test
lineinfile:
path: /tmp/out.log
regexp: “{{ item.item }}”
state: absent
check_mode: yes
changed_when: false
register: checklog
with_items:
{ item: “^v=1”}
{ item: “^s=Kurento Media Server” }
{ item: “^IceCandidateFound” }
{ item: “^IceGatheringDone” }
failed_when: not checklog.found
The failing line is “v=1”, because it is “v=0”. The rest of the lines except the last is there. Result: