I currently have a role that I am trying to tailor to install a splunk forwarder on both Linux and Windows machines but I’m a little confused as to how I should be telling the main.yml to yes go target these other two tasks splunklinux.yml if it’s a RedHat Linux distribution or go to splunkwindows.yml to target Windows.
I found the following logic:
when: ansible_os_family == “Windows”
when: ansible_distribution == “RedHat”
But I’m unclear of whether this is the correct approach or not and also whether or not I need to provide further logic so Ansible knows that yes this machine is a windows machine or this machine is a linux machine. I’d rather keep it all under one role if I can.
In your main.yml put in include_tasks: windows.yml when the host is Windows and include_tasks: unix.yml when it is not. You can use the gathered facts to do this or you can have a variable that can be set when running on Windows by the end user.
Personally I think you should still split the role into 2, Windows is really not interoperable with the Unix side and they use their own modules. You would get quite a large and messy role when trying to handle both and it could become quite complex when implementing and documenting features that one supports and the other doesn’t. I had a lot of success doing this previously where there would be a java role and I would create a win-java role which tried to implement the same functionality where I could.
I’d back this up I have win- roles and linux- roles
Bear in mind you can run multiple plays in one playbook, targeting different host groups. Also since a linux host isn’t ever also a windows host you can probably run playbooks in parallel, even if they are installing the same ‘thing’ such as the splunk forwarder.