hosts per role?

We can do something like:

- hosts: group1
  roles:
    - role1

- hosts: group1:group2
  roles:
    - role2

- hosts: group2
  roles:
    - role3

etc, in a playbook. Would it be somehow possible to assign hosts "per role"? Something like:

- hosts: group1
  roles:
    - { role1, hosts: group3 }
    - { role2 }
    - { role3 }
    - { role4, hosts: group4 }

? The above doesn't seem to work :wink:

I’m not sure I understand what it is your trying to do here…

If you are trying to have some hosts execute another group’s role, you can use includes.
Otherwise, if you can explain why you are nesting group3/4 under roles when you have group1 set as hosts.