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.

On Wed, Nov 3, 2021, 00:27 'Neil Young' via Ansible Project <
[email protected]> wrote:

> Oops. Disregard please:
>
> regexp: "{{ item.item }}"
>
> Neil Young schrieb am Mittwoch, 3. November 2021 um 01:19:20 UTC+1:
>
>> One of the most recommended things is to use "lineinfiles" with some
>> special attributes for just finding a line in a file.
>>
>> I have a weird issue with this. If I just lookup one line, like so:
>>
>>  - name: TEST - Check /tmp/out.log
>>       lineinfile:
>>         path: /tmp/out.log
>>         regexp: "^bla"
>>         state: absent
>>       check_mode: yes
>>       changed_when: false
>>       register: checklog
>>       failed_when: not checklog.found
>>
>> 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...
>>
>>
>>   - name: TEST - Check /tmp/out.log
>>       lineinfile:
>>         path: /tmp/out.log
>>         regexp: "{{ item }}"
>>         state: absent
>>       check_mode: yes
>>       changed_when: false
>>       register: checklog
>>       with_items:
>>         - {item: "^line1"}
>>         - {item: "^line2"}
>>         - {item: "^line3"}
>>         - {item: "^line4"}
>>         - {item: "^bla"}
>>       failed_when: not checklog.found
>>
>> Does that make sense at all?
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/e1146c52-8a89-4634-a212-e9bc8ab07b30n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/e1146c52-8a89-4634-a212-e9bc8ab07b30n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFtje5ONeoJPBHpZPmHed6fKn5KMNViTgq-jMQ606r3yk0D8sA%40mail.gmail.com.

Reply via email to