# role with in a role

**URL:** <https://forum.ansible.com/t/role-with-in-a-role/38033>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [May 26, 2023, 5:24pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033 "2023-05-26T17:24:10Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [May 26, 2023, 5:24pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/1 "2023-05-26T17:24:10Z")

</div>

I am trying a playbook for a role and calling another role with in it.  
role1 where i am running playbook need to be executed on windows hosts, role 2 which is being called in role1 needs to be executed on localhost(linux).  
this is from the tasks/main.yml file for role1.  
but still it is picking windows node from role1 and failing…

- name: calling serverdata role here  
include\_role:  
name: serverdata (role2)  
tasks\_from: main.yml  
apply:  
delegate\_to: localhost

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [May 26, 2023, 5:34pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/2 "2023-05-26T17:34:15Z")

</div>

I haven’t tried this myself (as it sounds too complicated and error prone), but I’m guessing because you first run on the remote Windows host, and from there during the other role, localhost is in fact that remote host.  
It makes sense, in a way.

I may be completely wrong though

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [May 26, 2023, 5:47pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/3 "2023-05-26T17:47:42Z")

</div>

local host is the ansible master where the role2 has to be executed. because the role2 is to run some api commands and get server details  
role1` is to install components on the server which I get from role2

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [May 30, 2023, 7:42pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/4 "2023-05-30T19:42:28Z")

</div>

any suggestions please to satisfy my above request…

---

<div class="post-metadata">

**Author:** ![Kosala\_Atapattu1](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kosala\_Atapattu1](https://forum.ansible.com/u/Kosala_Atapattu1)\
**Post date:** [May 30, 2023, 11:24pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/5 "2023-05-30T23:24:10Z")

</div>

I’ve done this before for a complicated piece of work I did. I had roles running on several delegate proxies (yeah I called them that, since we had 5-6 of them :)).

However I did not delegate a role in mycase, but all the tasks were written with delegate\_to: “{{ delgate\_host }}” where I can override delegate\_host variable at the role level.

I do not believe this is a widely used regime, and I did ran in to some issues when you call role → role → role, the last layer lost visibility to all the top level variables. Like @Dick Visser said this will not be the smoothest sailing, but surely works.

I wrote this originally for Ansible 2.9, but when I tested with 2.11, most of the issues I faced were gone.

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [May 31, 2023, 3:31pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/6 "2023-05-31T15:31:51Z")

</div>

So, is there any other alternate solution you would suggest for my requirement.

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [May 31, 2023, 4:54pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/7 "2023-05-31T16:54:39Z")

</div>

Something without the nested roles, as those are clearly not doing  
what you want.  
It's a bit hard to understand what needs to be executed where.  
I would start out with a playbook and not bother with roles initially.

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [May 31, 2023, 5:58pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/8 "2023-05-31T17:58:01Z")

</div>

got it…  
thankyou

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [June 1, 2023, 2:49pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/9 "2023-06-01T14:49:51Z")

</div>

I have one more question please, can we call a play in another play, because I have a playbook which needs to run some curl commands and fetch data, and the second play book has to perform the configurations.  
When I want to run configuration playbook, first it needs to run curl playbook and fetch data.

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [June 1, 2023, 5:14pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/10 "2023-06-01T17:14:51Z")

</div>

You can have a playbook with multiple plays. One targets localhost to fetch api results. You register that.  
The subsequent plays target real host and use the registered data

---

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [June 1, 2023, 6:05pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/11 "2023-06-01T18:05:53Z")

</div>

import\_plays and import\_playbook

Mike

---

<div class="post-metadata">

**Author:** ![Kosala\_Atapattu1](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kosala\_Atapattu1](https://forum.ansible.com/u/Kosala_Atapattu1)\
**Post date:** [June 1, 2023, 8:10pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/12 "2023-06-01T20:10:42Z")

</div>

I think the command module now complain as well, uri module is a native way to do what curl does.

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [June 2, 2023, 8:46pm UTC](https://forum.ansible.com/t/role-with-in-a-role/38033/13 "2023-06-02T20:46:09Z")

</div>

Thanks Dick for explaining it, my first problem solved - I converted everything back to playbooks and able to call 2 playbooks, on will be running on localhost and second playbooks runs on windows.  
second scenario where I need some advise, from one of my playbook I get all servers and I am saving it as yaml. I want to call that server.yml as inventory when running second playbook… but the server.yml has to access the groups\_vars, where it has all variables… how can I have them??
