# Newbie question regarding playbook execution logic

**URL:** <https://forum.ansible.com/t/newbie-question-regarding-playbook-execution-logic/24047>\
**Category:** Ansible Project\
**Created:** [March 23, 2017, 5:54pm UTC](https://forum.ansible.com/t/newbie-question-regarding-playbook-execution-logic/24047 "2017-03-23T17:54:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![barnaclefluff](https://avatars.discourse-cdn.com/v4/letter/b/8edcca/32.png) [@barnaclefluff](https://forum.ansible.com/u/barnaclefluff)\
**Post date:** [March 23, 2017, 5:54pm UTC](https://forum.ansible.com/t/newbie-question-regarding-playbook-execution-logic/24047/1 "2017-03-23T17:54:40Z")

</div>

Hi,

i’m probably hitting a basic newbie misunderstanding here. What would be the best practice approach to write a playbook that does something like:  
Call a playbook like patch\_hosts.yml , targetting all hosts.  
patch\_hosts will run a yum update. But first, it’ll detect if the host is in a cluster, and if so, shutdown the cluster. If it’s running websphere, it’ll shut that down. If it’s running a DB, etc, etc.  
Then for the patching, it can also get funky: if it’s a cluster it’s going to yum update, then reboot, then patch the cluster, make some checks, etc. Same kind of complexity for websphere patching, and so forth. There could be a pile of fixes to apply in sequence that take quite some time.

Basically, in the end this playbook is branching out into other playbooks. In the end I’m running lots of tasks against lots of hosts.

The problem is, if I have 1000 hosts and 50 are going to install websphere\_patch\_123456, I’ll have 950 hosts that skip that task, but nevertheless wait for the 50 to complete. Same for clusters, same for other apps, etc.

End result, I have 1000 hosts running actions that, if individually run per host, might take 30 minutes, but because everyone is basically executing/skipping every task and waiting for each other, it ends up meaning the total time is going to almost be the sum of all the slowest tasks of the slowest hosts, run in sequence. It can end up absurdly long.

What’s the correct approach here? Is attempting to use a top-level “patch\_everything.yml” not the best practice? Or is there some “fork and forget and run everywhere individually” option? Note, I do not want to fire and forget individual _tasks_, I want to fire and forget the entire playbook against each host, as if I was doing a for x in hostlist ; do ansible-playbook xxx loop. Which I could do but seems like a very clunky workaround.

---

<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:** [March 23, 2017, 6:06pm UTC](https://forum.ansible.com/t/newbie-question-regarding-playbook-execution-logic/24047/2 "2017-03-23T18:06:57Z")

</div>

You have strategy, default is "linear" but Ansible also comes with "free" where a play is running as fast as it can on each host.  
[https://docs.ansible.com/ansible/playbooks\_strategies.html](https://docs.ansible.com/ansible/playbooks_strategies.html)

---

<div class="post-metadata">

**Author:** ![barnaclefluff](https://avatars.discourse-cdn.com/v4/letter/b/8edcca/32.png) [@barnaclefluff](https://forum.ansible.com/u/barnaclefluff)\
**Post date:** [March 24, 2017, 7:52am UTC](https://forum.ansible.com/t/newbie-question-regarding-playbook-execution-logic/24047/3 "2017-03-24T07:52:01Z")

</div>

That sounds like exactly what I need. Thanks!
