Hi,
So I've been scavenging through a lot of posts to figure out how to deal with heterogeneous environments.
The two approaches that I see most are either using "group_by" or using "when".
For example:
site.yml:
- name: whatever
tasks:
- group_by: key={{ansible_os_family}
- hosts: Debian
roles:
- role: rolename-debian
- hosts: Darwin
roles:
- role: rolename-darwin
My problem with this approach is that you are saying that a role is "OS" specific, even though it's not. Perhaps this has to do with my definition of role, but as I see it a 'role' is a task that any given node can perform.
I should be able to assign the 'role' 'nginx' to a variety of hosts, how those hosts then implement that role should be defined within the 'role' definition.
Now supposedly you can do this using the 'when' conditional statement, you would then end up with something like:
roles/myRole/tasks
- include: apt.yml
when: ansible_os_family == "Debian"
- include: brew.yml
when ansible_os_family == "Darwin"
However this is rather chatty, especially when these files include files of there own. And with chatty I mean every task, even when the 'when' clause is not matched is being shown, now you can set 'show_skipped_hosts" in the ansible configuration, however this still shows the headers of tasks that are (not) being processed.
Should I be dealing with this in a different fashion?
What I'm trying to accomplish is having a playbook that installs a package on a bunch of machines (running differents OS's), then configure that package based on the OS and configure the service accordingly.
IMHO the latter approach is the way to go, however the 'chattyness' is killing my operators.
Thanks a lot for sharing your insights.
Best regards.