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. 

On Thursday, October 20, 2022 at 12:27:11 AM UTC-7 [email protected] wrote:

> 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
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fdf778c2-188d-43a5-8c9c-93c1d16977dcn%40googlegroups.com.

Reply via email to