# Include\_tasks and loops break parallelism

**URL:** <https://forum.ansible.com/t/include-tasks-and-loops-break-parallelism/11006>\
**Category:** Get Help\
**Tags:** ansible-core\
**Created:** [November 19, 2024, 8:16pm UTC](https://forum.ansible.com/t/include-tasks-and-loops-break-parallelism/11006 "2024-11-19T20:16:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MalfuncEddie](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/malfunceddie/32/428_2.png) [@MalfuncEddie](https://forum.ansible.com/u/MalfuncEddie)\
**Post date:** [November 19, 2024, 8:16pm UTC](https://forum.ansible.com/t/include-tasks-and-loops-break-parallelism/11006/1 "2024-11-19T20:16:44Z")

</div>

**Situation:**

Multiple servers with each one having multiple databases:

inventory file

```auto
serverA dbs='["db1","db2"]' 
serverB dbs='["db3","db4","db5"]' 

```

**What I want**  
to perform task in parallel at host but sequential per DB:

**What I tried**  
main.yml

```auto
- name: testcase
  hosts: all
  gather_facts: yes

  tasks:
    - name: "Patching DB"
      include_tasks:
        file: patch_db.yml
      vars:
        - db: '{{ item }}'
      loop: "{{ dbs }}"

```

patch\_db.yml

```auto
- name: Patch DB
  debug:
    msg: "patching {{ ansible_host }} and DB {{ db }}"

```

**What I got**

```auto
PLAY [testcase] ******************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************
ok: [serverB]
ok: [serverA]

TASK [Patching DB] ***************************************************************************************************************************************
included: patch_db.yml for serverA => (item=db1)
included: patch_db.yml for serverA => (item=db2)
included: patch_db.yml for serverB => (item=db3)
included: patch_db.yml for serverB => (item=db4)
included: patch_db.yml for serverB => (item=db5)

TASK [Patch DB] ******************************************************************************************************************************************
ok: [serverA] => {
    "msg": "patching serverA and DB db1"
}

TASK [Patch DB] ******************************************************************************************************************************************
ok: [serverA] => {
    "msg": "patching serverA and DB db2"
}

TASK [Patch DB] ******************************************************************************************************************************************
ok: [serverB] => {
    "msg": "patching serverB and DB db3"
}

TASK [Patch DB] ******************************************************************************************************************************************
ok: [serverB] => {
    "msg": "patching serverB and DB db4"
}

TASK [Patch DB] ******************************************************************************************************************************************
ok: [serverB] => {
    "msg": "patching serverB and DB db5"
}

PLAY RECAP ***********************************************************************************************************************************************
serverA : ok=5 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
serverB : ok=7 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

```

Instead of splitting up the hosts and running in parallel it runs sequential

I’m hitting this bug/feature. [include\_tasks in a loop breaks task execution order · Issue #36978 · ansible/ansible · GitHub](https://github.com/ansible/ansible/issues/36978)

Is there another way to accomplish what I want?

Strategy free does solve this but makes it hard to read the logging.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [November 19, 2024, 8:44pm UTC](https://forum.ansible.com/t/include-tasks-and-loops-break-parallelism/11006/2 "2024-11-19T20:44:46Z")

</div>

For roles I’ve written that use loops like this (I didn’t understand and implications or `map` at the time…) I generally open a terminal / screen session per server, while this is inconvenient it does seem to be one way to speed things up, also each process seems to only use one CPU core so it is a way to make the most of available CPU resources. 🤷

---

<div class="post-metadata">

**Author:** ![MalfuncEddie](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/malfunceddie/32/428_2.png) [@MalfuncEddie](https://forum.ansible.com/u/MalfuncEddie)\
**Post date:** [November 19, 2024, 9:24pm UTC](https://forum.ansible.com/t/include-tasks-and-loops-break-parallelism/11006/3 "2024-11-19T21:24:05Z")

</div>

Yeah but I want to integrate it into awx.
