role with in a role

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

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

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

any suggestions please to satisfy my above request…

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.

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

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.

got it…
thankyou

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.

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

import_plays and import_playbook

Mike

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

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??