# Regarding Stopping Execution if condition met

**URL:** <https://forum.ansible.com/t/regarding-stopping-execution-if-condition-met/35982>\
**Category:** Ansible Project\
**Created:** [November 10, 2021, 6:18am UTC](https://forum.ansible.com/t/regarding-stopping-execution-if-condition-met/35982 "2021-11-10T06:18:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akshay\_Jadhav](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@Akshay\_Jadhav](https://forum.ansible.com/u/Akshay_Jadhav)\
**Post date:** [November 10, 2021, 6:18am UTC](https://forum.ansible.com/t/regarding-stopping-execution-if-condition-met/35982/1 "2021-11-10T06:18:44Z")

</div>

Hi Guys,  
I want to add a condition to stop execution of playbook if “vlan not found”. I am attaching my playbook tasks below:

- name: check vlan availability  
ios\_command:  
commands:

- show vlan id {{ vlan1 }}  
register: precheck

- name: check voice\_vlan availability  
ios\_command:  
commands:

- show vlan id {{ vlan2 }}  
register: precheck\_voice\_vlan

- name: L2 Vlan1 Availability Check  
debug:  
msg: “Vlan not present in the switch”  
when: “‘not found’ in precheck”

- name: L2 Vlan2 Availability Check  
debug:  
msg: “Vlan not present in the switch”  
when: “‘not found’ in precheck\_voice\_vlan”

===========here I want stop playbook execution if vlan not found========

- name: get interface status from the device  
ios\_command:  
commands:
- show run int {{ interface }} | i trunk  
register: precheck\_int

if Vlan not found in precheck I want to stop further execution .Please help me for this.

---

<div class="post-metadata">

**Author:** ![Roberto\_J\_R\_Paz](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@Roberto\_J\_R\_Paz](https://forum.ansible.com/u/Roberto_J_R_Paz)\
**Post date:** [November 10, 2021, 12:24pm UTC](https://forum.ansible.com/t/regarding-stopping-execution-if-condition-met/35982/2 "2021-11-10T12:24:15Z")

</div>

You should check “end\_play”:

- block:

- name: Closing tasks  
…

- meta: end\_play  
when: vlan\_not\_present\_condition

This will end the playbook completely.

---

<div class="post-metadata">

**Author:** ![Jack\_Morgan](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@Jack\_Morgan](https://forum.ansible.com/u/Jack_Morgan)\
**Post date:** [November 10, 2021, 6:56pm UTC](https://forum.ansible.com/t/regarding-stopping-execution-if-condition-met/35982/3 "2021-11-10T18:56:41Z")

</div>

You might also look at changed\_when or failed\_when. Here are some examples.

[https://www.middlewareinventory.com/blog/ansible-changed\_when-and-failed\_when-examples/](https://www.middlewareinventory.com/blog/ansible-changed_when-and-failed_when-examples/)
