# Is it possible to avoid aborting a play if all hosts in a serial batch fail?

**URL:** <https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870>\
**Category:** Ansible Project\
**Created:** [February 28, 2018, 9:09pm UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870 "2018-02-28T21:09:02Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Heffner](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Daniel\_Heffner](https://forum.ansible.com/u/Daniel_Heffner)\
**Post date:** [February 28, 2018, 9:09pm UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/1 "2018-02-28T21:09:02Z")

</div>

So, for example, i have a playbook:

`

- hosts: some\_hosts  
serial: 50  
roles:
- some\_role

… some other play with different hosts  
`

and for some reason, all 50 hosts in a batch fail. I want to continue running the play on the rest of the hosts in the some\_hosts group, and continue on to the rest of the plays in the playbook.

I’ve tried adding max\_fail\_percentage: 100 but I suppose it was too much to hope that that would be a way to hack around the issue.

Anyone know of a way to do this?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 1, 2018, 12:13am UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/2 "2018-03-01T00:13:49Z")

</div>

That is because serial is specifically set to kill play if all hosts  
in a batch fail, mail\_fail\_percentage is calculated on the serial  
batch, not the full list of hosts for the play.

I would ask, why are you using serial if you don't want the feature?

---

<div class="post-metadata">

**Author:** ![Daniel\_Heffner](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Daniel\_Heffner](https://forum.ansible.com/u/Daniel_Heffner)\
**Post date:** [March 1, 2018, 12:18am UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/3 "2018-03-01T00:18:07Z")

</div>

short answer, I’m trying to solve an issue where I run out of memory parsing output by limiting the number of hosts being processed at one time.

isn’t the feature of serial the ability to run through hosts in batch, not the behavior of killing a playbook run if some of the hosts fail?

---

<div class="post-metadata">

**Author:** ![Daniel\_Heffner](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Daniel\_Heffner](https://forum.ansible.com/u/Daniel_Heffner)\
**Post date:** [March 1, 2018, 12:24am UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/4 "2018-03-01T00:24:21Z")

</div>

also, the documentation specifically says that max\_fail\_percentage needs to be exceeded. you can’t exceed 100%, so I hoped that would work.

I suppose this behavior is nonsensical to me. If I was baking cookies and got halfway through the dough when I completely burned one batch, I wouldn’t just toss out the rest of the cookie dough and then refuse to make dinner.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 1, 2018, 12:33am UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/5 "2018-03-01T00:33:18Z")

</div>

If you are doing it for memory issues, I believe you just want --forks  
50 instead.

---

<div class="post-metadata">

**Author:** ![Daniel\_Heffner](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Daniel\_Heffner](https://forum.ansible.com/u/Daniel_Heffner)\
**Post date:** [March 1, 2018, 12:42am UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/6 "2018-03-01T00:42:37Z")

</div>

isn’t the default forks=5? it doesn’t seem like increasing the number of parallel processes would address the issue of running g out of memory while parsing text output from hundreds of hosts

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 1, 2018, 12:46am UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/7 "2018-03-01T00:46:08Z")

</div>

Yes, that is the default, not sure how serial 50 helps with the memory  
then, as Ansible always uses the lowest number of the 2.

---

<div class="post-metadata">

**Author:** ![Daniel\_Heffner](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Daniel\_Heffner](https://forum.ansible.com/u/Daniel_Heffner)\
**Post date:** [March 1, 2018, 12:50am UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/8 "2018-03-01T00:50:01Z")

</div>

serial=50 means than instead of trying to parse and hold in memory text output from over 500 hosts, you only have to do it for 50 at a time.

unless the documentation is severely confusing, forks and serial are not the same thing. forks is number of hosts to run in parallel, serial is how many hosts to put through the play at until the list of hosts is exhausted

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 1, 2018, 1:00am UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/9 "2018-03-01T01:00:16Z")

</div>

Yes, but if you set --forks 500 and serial 50, ansible will only fork  
on the lower number, this is sometimes used as a fork limiter  
(incorrectly) which is what i assumed you were doing.

Serial will batch the hosts to run through play, but that should not  
create less/more memory consumption unless its bringing down the  
number of forks.

---

<div class="post-metadata">

**Author:** ![Daniel\_Heffner](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Daniel\_Heffner](https://forum.ansible.com/u/Daniel_Heffner)\
**Post date:** [March 1, 2018, 1:20am UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/10 "2018-03-01T01:20:17Z")

</div>

so let’s pretend the task list is

1. ssh to the host and execute a command that returns a large amount of text
2. parse that text into json
3. send the json to an API

consider the difference between holding 50 objects that each take up 5 mb and possibly over 500 objects that each take up 5 mb. that’s why I’m trying to use serial - to limit the amount of memory I have to use at each step.

because I love metaphors:  
I have to carry 500 bags from point A, put something in them at point B, and drop them off at point C. I’m not strong enough to carry all 500 filled bags at once, but I can string 10 on my arms, so I carry 10 at a time - I split them into batches. If at one point, all 10 bags that I’m carrying broke, I’m not going to give up and leave the rest of the bags unfilled and untransported. that’s how I want to use serial: to limit the weight my server has to carry at any given time.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 1, 2018, 2:47am UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/11 "2018-03-01T02:47:00Z")

</div>

That assumes ansible does not hold registred data until the end of the  
run, but instead clears it when the host is done in play, that is an  
incorrect assumption.

---

<div class="post-metadata">

**Author:** ![Daniel\_Heffner](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Daniel\_Heffner](https://forum.ansible.com/u/Daniel_Heffner)\
**Post date:** [March 1, 2018, 3:06am UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/12 "2018-03-01T03:06:53Z")

</div>

that’s a good point, and it indicates that I’m probably barking up the wrong tree with serial and I just need to increase the memory on the VM.

it doesn’t answer why there’s no way to set a playbook to continue even if a serial batch fails, but I suppose that’s irrelevant to me now.

---

<div class="post-metadata">

**Author:** ![Josh\_Smift2](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Josh\_Smift2](https://forum.ansible.com/u/Josh_Smift2)\
**Post date:** [March 1, 2018, 1:59pm UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/13 "2018-03-01T13:59:10Z")

</div>

This is a good metaphor, and I’ve never understood why `serial` works this way. We’ve repeatedly had situations where we want to do things on a few hosts at a time, and continue even if one batch of them fails – especially if the batch size is 1 – and there’s just no way to do that.

I understand the use cases for wanting to fail if all your batches fail: To stick with your metaphor, maybe all ten bags in your batch broke, you stumbled, and sprained your ankle. At that point, you _do_ want to stop, and not hurt yourself more.

That should be a decision that you can make on a case-by-case basis, though; saying “any failure == stop the whole play” seems obviously wrong. (And there are lots of other places where you can control how much failure == stop the whole play; this is just a weird exception to that principle.)

---

<div class="post-metadata">

**Author:** ![Josh\_Smift2](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Josh\_Smift2](https://forum.ansible.com/u/Josh_Smift2)\
**Post date:** [March 1, 2018, 2:01pm UTC](https://forum.ansible.com/t/is-it-possible-to-avoid-aborting-a-play-if-all-hosts-in-a-serial-batch-fail/26870/14 "2018-03-01T14:01:40Z")

</div>

Oops, I misspoke here: I meant "the use cases for wanting to fail the whole play if all the hosts _in one batch_ fail.

To switch back to the cookies metaphor: Sometimes that’s what you want (your oven caught fire); sometimes it’s not (you burned one batch).
