# Having trouble using with\_items, delegate\_to and run\_once to fake having serial: 1 on an include in a role

**URL:** <https://forum.ansible.com/t/having-trouble-using-with-items-delegate-to-and-run-once-to-fake-having-serial-1-on-an-include-in-a-role/22794>\
**Category:** Ansible Project\
**Created:** [October 14, 2016, 8:20pm UTC](https://forum.ansible.com/t/having-trouble-using-with-items-delegate-to-and-run-once-to-fake-having-serial-1-on-an-include-in-a-role/22794 "2016-10-14T20:20:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stig\_Dossing](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@Stig\_Dossing](https://forum.ansible.com/u/Stig_Dossing)\
**Post date:** [October 14, 2016, 8:20pm UTC](https://forum.ansible.com/t/having-trouble-using-with-items-delegate-to-and-run-once-to-fake-having-serial-1-on-an-include-in-a-role/22794/1 "2016-10-14T20:20:21Z")

</div>

I’m trying to use the approach described here [https://github.com/ansible/ansible/issues/12170](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?

---

<div class="post-metadata">

**Author:** ![Stig\_Dossing](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@Stig\_Dossing](https://forum.ansible.com/u/Stig_Dossing)\
**Post date:** [October 14, 2016, 10:12pm UTC](https://forum.ansible.com/t/having-trouble-using-with-items-delegate-to-and-run-once-to-fake-having-serial-1-on-an-include-in-a-role/22794/2 "2016-10-14T22:12:00Z")

</div>

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.
