# How to stop the play only for one hostgroup if any one host failed in that hostgroup ?

**URL:** <https://forum.ansible.com/t/how-to-stop-the-play-only-for-one-hostgroup-if-any-one-host-failed-in-that-hostgroup/27659>\
**Category:** Ansible Project\
**Created:** [May 30, 2018, 2:17am UTC](https://forum.ansible.com/t/how-to-stop-the-play-only-for-one-hostgroup-if-any-one-host-failed-in-that-hostgroup/27659 "2018-05-30T02:17:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Venkatsm\_V](https://avatars.discourse-cdn.com/v4/letter/v/b2d939/32.png) [@Venkatsm\_V](https://forum.ansible.com/u/Venkatsm_V)\
**Post date:** [May 30, 2018, 2:17am UTC](https://forum.ansible.com/t/how-to-stop-the-play-only-for-one-hostgroup-if-any-one-host-failed-in-that-hostgroup/27659/1 "2018-05-30T02:17:40Z")

</div>

Hi,

Instead of passing to specific hostgroup, can i pass the regex to “hosts: ” for the play hosts ?.

eg:-

- name: pre-step of the setup process  
hosts: cluster\_.\*  
gather\_facts: false  
strategy: free  
any\_errors\_fatal: true  
tasks:
- include : roles/setup\_node/tasks/pre-setup.yml

Basically i have dynamic hosts group name prefix with “cluster\_”. The above method of regex way is not working ?. any tricks or best practices to get the dynamic inventory.

another requirement:-  
[cluster\_x1]  
host1  
host2

[cluster\_x2]  
host3  
host4

In the above host inventory file, if host2 fails on play, i would like to not to consider other tasks in the play for both host1, host2 for cluster cluster\_x1. Is that possible ?.

Thanks  
venkat

---

<div class="post-metadata">

**Author:** ![David\_Villasmil](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@David\_Villasmil](https://forum.ansible.com/u/David_Villasmil)\
**Post date:** [May 30, 2018, 12:23pm UTC](https://forum.ansible.com/t/how-to-stop-the-play-only-for-one-hostgroup-if-any-one-host-failed-in-that-hostgroup/27659/2 "2018-05-30T12:23:48Z")

</div>

Never done it, but i think you can use limit:

[https://ansible-tips-and-tricks.readthedocs.io/en/latest/ansible/commands/](https://ansible-tips-and-tricks.readthedocs.io/en/latest/ansible/commands/)

---

<div class="post-metadata">

**Author:** ![Storeng99](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@Storeng99](https://forum.ansible.com/u/Storeng99)\
**Post date:** [May 30, 2018, 9:59pm UTC](https://forum.ansible.com/t/how-to-stop-the-play-only-for-one-hostgroup-if-any-one-host-failed-in-that-hostgroup/27659/3 "2018-05-30T21:59:33Z")

</div>

Hi ,

limit:1  
max\_fail\_percent:0

This should help you as it will limit the number of hosts your playbook is run as well if it fails it will not run on any more hosts .

dynamic inventory i am still trying to understand it ,

Here is a link from which can help you

[docs.ansible.com/ansible/latest/user\_guide/intro\_dynamic\_inventory.html](http://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html)

ta

---

<div class="post-metadata">

**Author:** ![Venkatsm\_V](https://avatars.discourse-cdn.com/v4/letter/v/b2d939/32.png) [@Venkatsm\_V](https://forum.ansible.com/u/Venkatsm_V)\
**Post date:** [May 30, 2018, 10:14pm UTC](https://forum.ansible.com/t/how-to-stop-the-play-only-for-one-hostgroup-if-any-one-host-failed-in-that-hostgroup/27659/4 "2018-05-30T22:14:27Z")

</div>

True. I can make it to max\_fail\_percent:99 to get it fail if any one fails. but hosts regex part is still in question to me ☹

Thanks  
venkat

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 30, 2018, 10:53pm UTC](https://forum.ansible.com/t/how-to-stop-the-play-only-for-one-hostgroup-if-any-one-host-failed-in-that-hostgroup/27659/5 "2018-05-30T22:53:49Z")

</div>

It doesn't support regex but pattern, all about it in the docs  
[https://docs.ansible.com/ansible/latest/user\_guide/intro\_patterns.html](https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html)
