# Abort entire run at one task failure

**URL:** <https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420>\
**Category:** Ansible Project\
**Created:** [September 4, 2013, 11:01pm UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420 "2013-09-04T23:01:55Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rumen\_Telbizov](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@Rumen\_Telbizov](https://forum.ansible.com/u/Rumen_Telbizov)\
**Post date:** [September 4, 2013, 11:01pm UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/1 "2013-09-04T23:01:55Z")

</div>

Hello everyone,

I have a rolling upgrade performed over an inventory of say 20 hosts.The playbook that runs this uses serial: 3, so 3 hosts only are being upgraded at a time.

What I want to achieve right now is: for any given batch of 3 hosts - if any one of those fails (any task) then present a prompt to the user and allow to abort the entire run - i.e. terminate and skip the remaining hosts in the inventory.

As far as I can tell the "prompt: " module is the _only_ way for me to abort the entire run of those 20 hosts (or whatever is left at the point of the failure). It pauses at the end of each 3 and waits. What I am missing is a way to detect if any of those 3 failed or not.I want to present that prompt _only_ if one of those three hosts has failed. If none failed - continue straight to the next batch of 3.

Since the prompt task is at the end of the playbook it’s not even executed if any task before it fails. I don’t want to have “ignore\_errors: True” everywhere since I do want the playbook to terminate and not continue.

As if I need a section which is executed at the end of each batch and I need to test if _anything_ failed within that individual batch.

I hope it makes sense. I can elaborate.

Thank you,

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 5, 2013, 12:18am UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/2 "2013-09-05T00:18:53Z")

</div>

You can set the attribute “max\_fail\_percentage” on a 1.3 playbook and control the amount of failures to tolerate in a single batch size from within a rolling update.

There is also “any\_errors\_fatal: True” which is not specific to the “serial” keyword, and can also cause failures on exactly 1 failure.

---

<div class="post-metadata">

**Author:** ![Rumen\_Telbizov](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@Rumen\_Telbizov](https://forum.ansible.com/u/Rumen_Telbizov)\
**Post date:** [September 5, 2013, 1:02am UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/3 "2013-09-05T01:02:57Z")

</div>

Thank you Michael,

That would do what I am aiming at.

I just tested this and I get an exception:

With “ **any\_errors\_fatal: True** ” :

TASK: [fail FAIL] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [[hostname.com](http://hostname.com)]  
failed: [[hostname.com](http://hostname.com)] =\> {“failed”: true}  
msg: Failed as requested from task  
Traceback (most recent call last):  
File “/usr/local/bin/ansible-playbook”, line 268, in   
sys.exit(main(sys.argv[1:]))  
File “/usr/local/bin/ansible-playbook”, line 208, in main  
pb.run()  
File “/Library/Python/2.7/site-packages/ansible/playbook/ **init**.py”, line 262, in run  
if not self.\_run\_play(play):  
File “/Library/Python/2.7/site-packages/ansible/playbook/ **init**.py”, line 580, in \_run\_play  
if (hosts\_count - len(host\_list)) \> int((play.max\_fail\_pct)/100.0 \* hosts\_count):  
TypeError: object of type ‘NoneType’ has no len()

This is “ **max\_fail\_percentage: 0** ” it works OK.

I have “ **serial: 2** ” in both cases.  
Let me know if I can be of any help tracking down this issue.

Regards,  
Rumen Telbizov

---

<div class="post-metadata">

**Author:** ![Kavin\_Kankeshwar](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@Kavin\_Kankeshwar](https://forum.ansible.com/u/Kavin_Kankeshwar)\
**Post date:** [September 5, 2013, 1:14am UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/4 "2013-09-05T01:14:39Z")

</div>

Hi Rumen,

That is a bug, When i added the feature (max\_fail\_percentage) , i did not test with “any\_errors\_fatal” . (sorry i never used that before)

Easy way would be to skip evaluation is host\_list is None. Thoughts ?

---

<div class="post-metadata">

**Author:** ![Kavin\_Kankeshwar](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@Kavin\_Kankeshwar](https://forum.ansible.com/u/Kavin_Kankeshwar)\
**Post date:** [September 5, 2013, 1:34am UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/5 "2013-09-05T01:34:40Z")

</div>

Rumen:

Would you be willing to help to test the fix? When both max\_fail\_percentage and any\_errors\_fatal is used ?

I just checked in a possible fix, (BUT have NOT yet tested the fix, As i need to get an environment up to test it.) If you already have the environment to test it up. Can you please test it and see if this fixes the issue ?

Git repo :  
[https://github.com/kavink/ansible](https://github.com/kavink/ansible)

Fix commit:

[https://github.com/kavink/ansible/commit/a075ec9831ba1096af41c1d8d20eaf1b8e2909f7](https://github.com/kavink/ansible/commit/a075ec9831ba1096af41c1d8d20eaf1b8e2909f7)

---

<div class="post-metadata">

**Author:** ![Rumen\_Telbizov](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@Rumen\_Telbizov](https://forum.ansible.com/u/Rumen_Telbizov)\
**Post date:** [September 5, 2013, 2:24am UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/6 "2013-09-05T02:24:07Z")

</div>

Hi Kavin,

---

<div class="post-metadata">

**Author:** ![Kavin\_Kankeshwar](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@Kavin\_Kankeshwar](https://forum.ansible.com/u/Kavin_Kankeshwar)\
**Post date:** [September 5, 2013, 2:35am UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/7 "2013-09-05T02:35:37Z")

</div>

Thanks, Fix should hopefully address your issue. So my analysis (Others can correct)

So whats happening is when you set any\_errors\_fatal as true, It makes host\_list as None and then immediately next it fails.

```auto

                if task.any_errors_fatal and len(host_list) < hosts_count:

                    host_list = None

                # If threshold for max nodes failed is exceeded , bail out.

                if (hosts_count - len(host_list)) > int((play.max_fail_pct)/100.0 * hosts_count):

                    host_list = None

```

---

<div class="post-metadata">

**Author:** ![Rumen\_Telbizov](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@Rumen\_Telbizov](https://forum.ansible.com/u/Rumen_Telbizov)\
**Post date:** [September 6, 2013, 4:59pm UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/8 "2013-09-06T16:59:17Z")

</div>

Hey Kavin, list,

I just tested your proposed fix and it is indeed working fine for me.

I’d suggest that you incorporate that fix in devel right now.

Michael, I was wondering now with the one week delay of the 1.3 release -

is this fix going to be part of the 1.3 release ?

Thanks,  
Rumen Telbizov

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 6, 2013, 5:04pm UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/9 "2013-09-06T17:04:14Z")

</div>

If we get a pull request on github, I can get this merged in before next Friday.

---

<div class="post-metadata">

**Author:** ![Rumen\_Telbizov](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@Rumen\_Telbizov](https://forum.ansible.com/u/Rumen_Telbizov)\
**Post date:** [September 6, 2013, 5:14pm UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/10 "2013-09-06T17:14:41Z")

</div>

That would be awesome. It would be nice if this bug doesn’t surface the release.

I believe Kavin can create the pull request but in case doesn’t I think you can incorporate his fix manually. Here’s the commit

[https://github.com/kavink/ansible/commit/a075ec9831ba1096af41c1d8d20eaf1b8e2909f7](https://github.com/kavink/ansible/commit/a075ec9831ba1096af41c1d8d20eaf1b8e2909f7)

It’s pretty simply (a few lines of change).

Cheers,  
Rumen Telbizov

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 6, 2013, 9:02pm UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/11 "2013-09-06T21:02:54Z")

</div>

any\_errors\_fatal may be reimplementable to just set max\_fail\_percentage to some episilon such as 0.00000000000001

Maybe not, just throwing that out there

---

<div class="post-metadata">

**Author:** ![Kavin\_Kankeshwar](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@Kavin\_Kankeshwar](https://forum.ansible.com/u/Kavin_Kankeshwar)\
**Post date:** [September 6, 2013, 11:51pm UTC](https://forum.ansible.com/t/abort-entire-run-at-one-task-failure/13420/12 "2013-09-06T23:51:03Z")

</div>

Just sent a pull request.

[https://github.com/ansible/ansible/pull/4058](https://github.com/ansible/ansible/pull/4058)
