---
- name: "Find the details here "
hosts: localhost
any_errors_fatal: true
serial: 1
tasks:
- name: Ansible find files multiple patterns examples
find:
paths: /home/examples
patterns: "*.db"
recurse: yes
register: files_matched
- name: Search for Number in the matched files
command: grep -i {{ myString }} {{ item.path }}
register: command_result
failed_when: command_result.rc == 0
with_items:
- "{{ files_matched.files }}"
- name: abort if string was found
meta: end_play
when: command is failed
It might be better to try the fail module since it will return the failed state you want:
- name: fail if string was found
fail:
msg: string was found!
when: command is failed