The technique I usually use for making a role work cross-distro is to do two things:
For variables: Include a variables file named {{ ansible_os_family }}.yml (then stick ‘Debian.yml’ and ‘RedHat.yml’, etc. into the role’s vars folder.
For tasks: Add “when: ansible_os_family == ‘Distribution’” to the task (where ‘Distribution’ is Debian, RedHat, etc.).
This presents an issue; for normal variables that I want to let role users override easily, I put the variables in the roles ‘defaults/main.yml’ file. But for distribution-specific variables (for example, “java_packages” in my Java role), I have to put the distro-specific vars include files in the main ‘vars’ folder, so those variables have higher precedence than, say, group_vars.
I’ve bumped into this a few times, but could usually find other ways of getting the variable I want to take hold. For some users, it’s not possible, thus I have bugs like: Openjdk-7 cannot be installed.
What are some possible fixes/other ways to do this?
I could set up a variable for each distro (like “java_redhat_packages” and “java_debian_packages”, but in some roles, where 5-10 of these would be needed, I fear maintainability and simplicity would be sacrificed for variable overridability…