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 <https://github.com/geerlingguy/ansible-role-java>), 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 
<https://github.com/geerlingguy/ansible-role-java/issues/1>.

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...

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d8e90023-a27d-4e71-962e-e8919aadfa83%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to