I wish to search for a string (“AC245”) in all files with extension *.db under /home/examples directory.
If the string is found I wish to abort the play immediately marking the playbook as FAILED.
Apart from aborting the play using “meta: end_play” I was able to achieve everything.
Can you help suggest how can I update my current code to add the end_play feature as soon as the string is found in any *.db file ?
---
- 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 }}"
You can run the above find.yml using this command: ansible-playbook find.yml -e “myString=AC245”