The only way to do this currently—while still preserving the ability for 
playbooks to override OS/environment-specific variables—is to use a little 
bit of a hack as is shown 
here: 
https://github.com/geerlingguy/ansible-role-apache/blob/master/tasks/main.yml#L1-L9

The goal of the proposal (
https://github.com/ansible/proposals/pull/21/commits) would be to make it 
so you don't have to add the extra set_fact task, nor use the '__varname' 
convention to indicate a variable that can be overridden.

I'm hoping this kind of thing could be supported in core Ansible someday, 
but for now, I've been using the hack/workaround for some time, and it's a 
passable solution.

-Jeff

On Thursday, July 14, 2016 at 11:51:01 AM UTC-5, Patrick Fink wrote:
>
> Hi all,
>
> I have a question regarding role default variables. First, this is my use 
> case: I want to develop reusable, redistributable and configurable roles 
> supporting different operating systems. Some variables differ on the 
> different operating systems. In addition to the defaults/main.yml file that 
> is always automatically loaded, I would like to have a variable file for 
> each operating system, something like rhel.yml, debian.yml etc. As the 
> roles should be redistributable, it should be easy to override these 
> variables, e.g. in the inventory or the playbook.
>
> I really like the approach mentioned in the Ansible Best Practices here: 
> http://docs.ansible.com/ansible/playbooks_best_practices.html#operating-system-and-distribution-variance,
>  
> but it's not on role level. If I would use include_vars, it would be very 
> hard to overwrite those role default variables. So the question is
>
> Is there any built-in mechanism to load more files than the main.yml from 
> a role defaults/ folder which keeps the variable precedence? And if yes, is 
> it possible to load them dynamically based on the operating system?
>
>
> Of course, I'm open to other ideas how to satisfy the use case and keep 
> roles portable, reusable and configurable without always having to modify 
> them.
>
>
> Thanks in advance,
> Patrick
>
>
>
>
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/cc78d521-d6c6-4d2f-80ae-168723ae9f4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to