# How to skip the playbook based on a condition

**URL:** <https://forum.ansible.com/t/how-to-skip-the-playbook-based-on-a-condition/32052>\
**Category:** Ansible Project\
**Created:** [January 24, 2020, 8:00pm UTC](https://forum.ansible.com/t/how-to-skip-the-playbook-based-on-a-condition/32052 "2020-01-24T20:00:51Z")\
**Posts on this page:** 3\
**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:00pm UTC](https://forum.ansible.com/t/how-to-skip-the-playbook-based-on-a-condition/32052/1 "2020-01-24T20:00:51Z")

</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:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [January 24, 2020, 8:37pm UTC](https://forum.ansible.com/t/how-to-skip-the-playbook-based-on-a-condition/32052/2 "2020-01-24T20:37:15Z")

</div>

meta: end\_play  
is what you want

[https://docs.ansible.com/ansible/latest/modules/meta\_module.html](https://docs.ansible.com/ansible/latest/modules/meta_module.html)

---

<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, 9:04pm UTC](https://forum.ansible.com/t/how-to-skip-the-playbook-based-on-a-condition/32052/3 "2020-01-24T21:04:43Z")

</div>

Thanks I got this working.
