# how to use Ansible meta module to halt playbook execution upon task Failure.

**URL:** <https://forum.ansible.com/t/how-to-use-ansible-meta-module-to-halt-playbook-execution-upon-task-failure/31034>\
**Category:** Ansible Project\
**Created:** [August 13, 2019, 8:27pm UTC](https://forum.ansible.com/t/how-to-use-ansible-meta-module-to-halt-playbook-execution-upon-task-failure/31034 "2019-08-13T20:27:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Easy\_King](https://avatars.discourse-cdn.com/v4/letter/e/c2a13f/32.png) [@Easy\_King](https://forum.ansible.com/u/Easy_King)\
**Post date:** [August 13, 2019, 8:27pm UTC](https://forum.ansible.com/t/how-to-use-ansible-meta-module-to-halt-playbook-execution-upon-task-failure/31034/1 "2019-08-13T20:27:20Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Zolvaring](https://avatars.discourse-cdn.com/v4/letter/z/ce73a5/32.png) [@Zolvaring](https://forum.ansible.com/u/Zolvaring)\
**Post date:** [August 16, 2019, 5:51am UTC](https://forum.ansible.com/t/how-to-use-ansible-meta-module-to-halt-playbook-execution-upon-task-failure/31034/2 "2019-08-16T05:51:59Z")

</div>

If you want to use meta it's simple but will not mark the play as failed, as far as I know there's no explicit way to do that with meta:

- name: abort if string was found  
&nbsp;&nbsp;meta: end\_play  
&nbsp;&nbsp;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  
&nbsp;&nbsp;fail:  
&nbsp;&nbsp;&nbsp;&nbsp;msg: string was found!  
&nbsp;&nbsp;when: command is failed
