Having trouble using with_items, delegate_to and run_once to fake having serial: 1 on an include in a role

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?

Tested this some more, and it seems to actually do what I expected. The include is run on both hosts once, sequentially. It seems a little weird that Ansible is showing the host as host1 → None instead of host1 → host1 or host1 → host2 for the debug tasks, but that’s only a minor problem. I’m wondering if that’s a bug or me doing something wrong. I tried replacing the role code with just a debug delegated to 127.0.0.1, and it’s still showing host1 → None.