# How to Stop playbook execution based on a file ?

**URL:** <https://forum.ansible.com/t/how-to-stop-playbook-execution-based-on-a-file/32053>\
**Category:** Ansible Developer\
**Created:** [January 24, 2020, 8:01pm UTC](https://forum.ansible.com/t/how-to-stop-playbook-execution-based-on-a-file/32053 "2020-01-24T20:01:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [January 24, 2020, 8:01pm UTC](https://forum.ansible.com/t/how-to-stop-playbook-execution-based-on-a-file/32053/1 "2020-01-24T20:01:25Z")

</div>

Hi,  
I basically wanted to skip the remaining of the playbook if a file exists

- name: Check if the file exists  
stat:  
path: /home/ansible/dbname/sql/file.sql  
register: optional\_file

- debug:  
msg: “File Exists”  
when: optional\_file.stat.exists == True

Also, Is there a way I read the same file, and based on a string I stop the remaining playbook?

---

<div class="post-metadata">

**Author:** ![td784](https://avatars.discourse-cdn.com/v4/letter/t/aeb1de/32.png) [@td784](https://forum.ansible.com/u/td784)\
**Post date:** [January 25, 2020, 2:06am UTC](https://forum.ansible.com/t/how-to-stop-playbook-execution-based-on-a-file/32053/2 "2020-01-25T02:06:11Z")

</div>

Depending on the overall scenario you can use the fail module. Otherwise, you’ll need to put conditionals on all other tasks in the playbook to just skip when the condition is not met.
