# Looping over include\_tasks serializes execution across the host batch

**URL:** <https://forum.ansible.com/t/looping-over-include-tasks-serializes-execution-across-the-host-batch/28176>\
**Category:** Ansible Project\
**Created:** [July 27, 2018, 8:59am UTC](https://forum.ansible.com/t/looping-over-include-tasks-serializes-execution-across-the-host-batch/28176 "2018-07-27T08:59:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ALF](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@ALF](https://forum.ansible.com/u/ALF)\
**Post date:** [July 27, 2018, 8:59am UTC](https://forum.ansible.com/t/looping-over-include-tasks-serializes-execution-across-the-host-batch/28176/1 "2018-07-27T08:59:04Z")

</div>

Hi,  
I wrote a role where I execute a task file for every interface of each target machine.  
Unfortunately, when reaching the loop the engine allows only one target at a time to execute the included tasks and stall the others with NOOP.  
How can I modify my code to have a normal linear flow (each task is performed on all the host at the same time)?

Info:  
Ansible 2.4.1  
Python 2.7.5  
Serial unset  
Default fork

---

<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:** [August 3, 2018, 6:02pm UTC](https://forum.ansible.com/t/looping-over-include-tasks-serializes-execution-across-the-host-batch/28176/2 "2018-08-03T18:02:16Z")

</div>

include\_task run on all host at the "same" time.  
The first task the include\_tasks is run on all host, default 5 hosts(fork) at the time.  
When the fist task is finished on all hosts, it run the second tasks on all hosts and so on.

There is no difference between ordinary task and task in include\_tasks.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [August 3, 2018, 7:43pm UTC](https://forum.ansible.com/t/looping-over-include-tasks-serializes-execution-across-the-host-batch/28176/3 "2018-08-03T19:43:02Z")

</div>

It’s a little hard to say based on the small amount of information you have given, however an `include_tasks` is uniquely defined by 3 items:

1. the file being included

2. the args passed to the include (in most cases this is just `item` from a loop)

3. the parent of the include

This uniqueness is done for several reasons, the most common, is that we aren’t sure whether deviations from this uniqueness may cause a file with a different number of tasks to be inserted.

As such, if `item` is different per host, this causes noop tasks to be inserted. Otherwise we would get out of sync between the task being executed and the task header that is printed.

This is something I have been working onaddressing  
, but have been delayed recently.It makes the assumption that as long as the filename is the same, that there are the same number of tasks within.

There is no toggle to change this behavior:

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

---

<div class="post-metadata">

**Author:** ![ALF](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@ALF](https://forum.ansible.com/u/ALF)\
**Post date:** [August 5, 2018, 10:03am UTC](https://forum.ansible.com/t/looping-over-include-tasks-serializes-execution-across-the-host-batch/28176/4 "2018-08-05T10:03:47Z")

</div>

Hi,

in my case the only changing factor is the array the include loops over, because I execute the inclusion for each selected network interface of each target.  
So, I had to switch the play strategy to “free” to speed up the deployment process. However, it would be nice to review the NOOP injection policy.  
Thanks.
