How to select hosts based on facts?

I wrote a role for Solaris systems. And now I would like to apply the role to all systems, which have been identified by Ansible to be a Solaris host.

I know that I can write an inventory group containing all Solaris servers. But this sounds redundant to me. Instead I want Ansible to check if the host is a Solaris host and if so, apply the role for Solaris systems.

How can this be done?

With when
https://docs.ansible.com/ansible/latest/playbooks_conditionals.html#the-when-statement

Cev Ing wrote:

I know that I can write an inventory group containing all Solaris servers. But this
sounds redundant to me. Instead I want Ansible to check if the host is a Solaris host
and if so, apply the role for Solaris systems.

Maybe this helps:

https://docs.ansible.com/ansible/latest/group_by_module.html

Ciao, Michael.

I dont think it is possible to use a when statement on a role. Are you sure?

That seems to fit. Thanks!

All the allowed directives for a role is listed here
https://docs.ansible.com/ansible/latest/playbooks_directives.html#role
and when is one of them.