Hi Jörg!
On 25-07-16 13:20, Jörg Kastning wrote:
> Dear all,
>
> I'd like to map a role to a group of hosts with a specific operating system.
This should be possible with a playbook somewhat along these lines:
First play working on the relevant hosts (not filtered by OS) with one
pre_task:
- name: group by OS
group_by: key=bla_bla_{{ [ansible_fact_for_OS_name] }} # (you may add
a default, if necessary)
changed_when: False
The you'll want to have a second play in the same playbook working on
one (or more) of the just defined group(s), like:
- hosts: bla_bla_Debian # (or bla_bla_Windows, or whatever)
roles:
- [add-your-role-here]
You'll get an output for all hosts of the bigger group of play one, but
play two will run for just that hosts you want it to run for. At least
this way it works for me - hope it helps.
Cheers, Kai
>
> So far I read Applying ‘when’ to roles and includes
> <
http://docs.ansible.com/ansible/playbooks_conditionals.html#applying-when-to-roles-and-includes>
> and the module description of group_by
> <
http://docs.ansible.com/ansible/group_by_module.html>. But I could not
> figure out how to use group_by to use a specific role only in cases
> where a variable matches an operating system. Could someone give an
> example, please?
>
> Do I have to set some group_var first to use with group_by?
>
> Kind regards,
> Joerg
>
> --
> You received this message because you are subscribed to the Google
> Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
ansible-proje...@googlegroups.com
> <mailto:
ansible-proje...@googlegroups.com>.
> To post to this group, send email to
ansible...@googlegroups.com
> <mailto:
ansible...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/ansible-project/9ea0b46e-d70d-422e-95c2-48e3136a9a58%40googlegroups.com
> <
https://groups.google.com/d/msgid/ansible-project/9ea0b46e-d70d-422e-95c2-48e3136a9a58%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit
https://groups.google.com/d/optout.