# blanket-apply delegate\_to to roles

**URL:** <https://forum.ansible.com/t/blanket-apply-delegate-to-to-roles/16420>\
**Category:** Ansible Project\
**Created:** [October 3, 2014, 5:12pm UTC](https://forum.ansible.com/t/blanket-apply-delegate-to-to-roles/16420 "2014-10-03T17:12:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [October 3, 2014, 5:12pm UTC](https://forum.ansible.com/t/blanket-apply-delegate-to-to-roles/16420/1 "2014-10-03T17:12:46Z")

</div>

I’ve got a case where I’d like to delegate contents of entire role over to another box. Adding “delegate\_to” to every task seems strenuous and not reusable since I may use this role without delegation.

My attempt at simulating what is done with { role: X, tags: A } did not succeed:

$ cat roles/delegated\_role/tasks/main.yml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 5, 2014, 6:02pm UTC](https://forum.ansible.com/t/blanket-apply-delegate-to-to-roles/16420/2 "2014-10-05T18:02:18Z")

</div>

Sounds like you should just configure that one server directly and missed the part of Ansible that allows managing specific host groups.

- hosts: name\_of\_server  
roles:
- …

What you have above, say if you had 500 hosts, would run each step 500 times and likely overwhelm that server.

---

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [October 7, 2014, 2:35pm UTC](https://forum.ansible.com/t/blanket-apply-delegate-to-to-roles/16420/3 "2014-10-07T14:35:47Z")

</div>

actually that is the intent. My example was “simplified” so it’s easy to understand mechanics of it, but obviously it’s hard to explain reasoning for doing it so. In other words instead of “hostname” there’s a command that does some “central registration” of each host, and it has to run from a central place. However in certain cases I can bypass that.

if I’m reading your comment correctly you propose to do:

- hosts: central\_server  
tasks:
- name: register other hosts  
shell: echo “{{ item }}” \>\> /tmp/registry  
with\_items: groups.X

however that disrupts the flow of the playbook and make my loops bit more complicated (for example where originally I’d have “with\_items” loop iterating over items to be applied to the host I now have to implement more complicated constructs like “with\_nested” etc.).

Also moving it out like that makes role not self-sufficient - i.e. if I want to recycle my role, I have to use the role that iterates over servers in a specified group or all.

---

<div class="post-metadata">

**Author:** ![Koteswara\_Rao\_Sakham](https://avatars.discourse-cdn.com/v4/letter/k/d07c76/32.png) [@Koteswara\_Rao\_Sakham](https://forum.ansible.com/u/Koteswara_Rao_Sakham)\
**Post date:** [June 24, 2017, 5:53pm UTC](https://forum.ansible.com/t/blanket-apply-delegate-to-to-roles/16420/4 "2017-06-24T17:53:22Z")

</div>

Hi Dmitry Makovey,  
Im also looking for the same solution, To run the play on other machine in the same task like this…

- hosts: webservers  
roles:
- { role: iinstall\_web}
- { role: delegated\_role, delegate\_to: “{{ central\_server }}” }

I have tried different options but failed. did you figured out how we can do this?
