# Quit a playbook without error for a particular host

**URL:** <https://forum.ansible.com/t/quit-a-playbook-without-error-for-a-particular-host/37249>\
**Category:** Ansible Project\
**Created:** [October 20, 2022, 7:27am UTC](https://forum.ansible.com/t/quit-a-playbook-without-error-for-a-particular-host/37249 "2022-10-20T07:27:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rai\_Ner](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@Rai\_Ner](https://forum.ansible.com/u/Rai_Ner)\
**Post date:** [October 20, 2022, 7:27am UTC](https://forum.ansible.com/t/quit-a-playbook-without-error-for-a-particular-host/37249/1 "2022-10-20T07:27:11Z")

</div>

Hi,

I have a playbook containing several Plays and each Play is executed on a bunch of hosts.

I would like to quit the whole playbook (not only the current play) for a particular host if a “when: condition” is met.

Example Playbook with 2 Plays:

- name: Play for patching precheck and download updates  
hosts: patchgroup  
remote\_user: ansible  
gather\_facts: true  
become: true  
timeout: 300  
roles:

- patching\_precheck\_download

- name: Play for setting Icinga downtime  
hosts: patchgroup  
remote\_user: ansible  
gather\_facts: true  
roles:

- role: icinga\_downtime  
vars:  
host\_and\_services: true

In the role patching\_precheck\_download there is the following task

- block:
- name: Red Hat | Quit playbook when no updates are found  
fail:  
msg: “Quit playbook for the current host since no updates are found.”  
#- meta: end\_host

when: updates.stdout\_lines | length == 0

If the when condition is met, I currently use “fail” which will end for the particular host, both the current play and the playbook. This is intended, but it will throw an error which should not be the case.

The other alternative I found is “meta: end\_host” this will not throw an error and end the play for the current host, but not for the whole Playbook (2nd Play will still be executed for this particular host). So, this is no solution.

Any ideas how to quit a Play and Playbook without throwing an error ?

Many thanks  
Rainer

---

<div class="post-metadata">

**Author:** ![Josh\_K](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@Josh\_K](https://forum.ansible.com/u/Josh_K)\
**Post date:** [October 20, 2022, 7:40pm UTC](https://forum.ansible.com/t/quit-a-playbook-without-error-for-a-particular-host/37249/2 "2022-10-20T19:40:06Z")

</div>

Perhaps one solution is to set some fact (with set\_fact) when this condition is met, like `finished: yes` and for subsequent plays/tasks you can add a line `when: finished is not defined`. Facts are set on a per-host basis, so I think this should work.

This isn’t really quitting, but it achieves the same result by skipping those tasks.
