multi-platform role support: setting vars according to OS

Hi,

I'm creating a role that supports multiple platforms and should handle
them transparently to the end user.

something like the following works fine for tasks/main.yml but doesn't
work for default/main.yml

- include: apt.yml
  when: ansible_pkg_mgr == 'apt'

What is the best way to set vars based on facts (while still
encapsulating it in a role)?

thanks!
Nusenu

Using that approach, the more platforms your hosts will sport, the more “skipping” you’ll see in your playbook runs.
I’d use the group_by module: http://docs.ansible.com/group_by_module.html and use the ansible_distribution fact as a key.
Hope that helps.

Hello Dan Vaida,

Dan Vaida wrote:

Using that approach, the more platforms your hosts will sport, the
more "skipping" you'll see in your playbook runs. I'd use the
group_by module: http://docs.ansible.com/group_by_module.html and
use the ansible_distribution fact as a key. Hope that helps.

thank you for your answer. The group_by - way to do this is also an
option for me but with that I can not encapsulate (and ship)
everything in a single role anymore (galaxy) and the OS split happens
in the playbook (instead of inside the role).

Is it uncommon to have a single role support multiple platforms with
such platform dependent includes as it was my intention?
I currently have 3 target platforms, in the future it might be four -
but certainly not more.

..but after all I still don't know how to assign platform dependent
vars within role/default/main.yml yet (my original question).

Dan Vaida wrote:

I think your other thread to which I replied is related to this as

well.

That is correct - so I merged them into one thread for simplicity.

Perhaps this example would be more helpful:

https://github.com/danvaida/Ansible-Berlin-Meetup/blob/master/ansible-intro-examples/ghost.yml

Ok, after some additional playing I got it, the trick is to specify
'-hosts:' again after running the group_by module.

recap:
NOT working