How to select hosts based on facts?

39 views
Skip to first unread message

Cev Ing

unread,
Aug 3, 2017, 12:01:08 PM8/3/17
to Ansible Project
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?

Kai Stian Olstad

unread,
Aug 3, 2017, 12:43:13 PM8/3/17
to ansible...@googlegroups.com

Michael Ströder

unread,
Aug 3, 2017, 12:58:36 PM8/3/17
to ansible...@googlegroups.com, Cev Ing
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.

Cev Ing

unread,
Aug 4, 2017, 1:13:10 AM8/4/17
to Ansible Project, ansible-pr...@olstad.com
I dont think it is possible to use a when statement on a role. Are you sure?

Cev Ing

unread,
Aug 4, 2017, 1:16:33 AM8/4/17
to Ansible Project, cev...@gmail.com, mic...@stroeder.com
That seems to fit. Thanks!
 
 

Kai Stian Olstad

unread,
Aug 4, 2017, 4:26:15 AM8/4/17
to ansible...@googlegroups.com
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.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages