I’m trying to use the approach described here https://github.com/ansible/ansible/issues/12170 to get part of a role to run serially. I am on 2.1.2.0, but have also tried 2.1.1.0 and 2.0.2.0.
`
- include: do_deploy.yml
with_items: “{{ play_hosts }}”
delegate_to: “{{ item }}”
run_once: true
`
do_deploy.yml simply contains
`
- debug: msg=“{{ item }}”
`
The role is being run from a playbook where hosts contains two hosts. I’d like this code to include do_deploy.yml once per host, and delegate each include to the host it’s currently iterating over.
I’m seeing this
`
TASK [deploy : include] *******************************************************
included: /home/stig/ansible/roles/deploy/tasks/do_deploy.yml for host1
included: /home/stig/ansible/roles/deploy/tasks/do_deploy.yml for host1
TASK [deploy : debug] *********************************************************
ok: [host1 → None] => {
“msg”: “host1”
}
TASK [deploy : debug] *********************************************************
ok: [host1 → None] => {
“msg”: “host2”
}
`
while I’d expect to see this
`
TASK [deploy : include] *******************************************************
included: /home/stig/ansible/roles/deploy/tasks/do_deploy.yml for host1
included: /home/stig/ansible/roles/deploy/tasks/do_deploy.yml for host2
TASK [deploy : debug] *********************************************************
ok: [host1 → None] => {
“msg”: “host1”
}
TASK [deploy : debug] *********************************************************
ok: [host2 → None] => {
“msg”: “host2”
}
`
Basically run_once seems to be acting like delegate_to isn’t being used.
Am I misusing delegate_to, or is there some other way to fake serial: 1 for an include?