Situation:
Multiple servers with each one having multiple databases:
inventory file
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
- 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
- name: Patch DB
debug:
msg: "patching {{ ansible_host }} and DB {{ db }}"
What I got
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
Is there another way to accomplish what I want?
Strategy free does solve this but makes it hard to read the logging.