Antoine,

Let's say for example you have your foobar role, and 

#defaults/main.yml
foobar_port: 42


And let's say you have an inventory group called "foobar" which is a list 
of all your foobar hosts.

By using the group_by module (http://docs.ansible.com/group_by_module.html) 
 in a previous play, you can dynamic create a group based on the OS (or any 
other fact)

Enter code here...
- group_by: key=machine_{{ ansible_distribution }}


You would also have a 

#group_vars/machine_Ubuntu 
foobar_port: 43

and a

#group_vars/machine_CentOS
foobar_port: 44


That would render the 43 or 44, overriding the default role value and be 
dependent on the OS.


- James


On Thursday, January 22, 2015 at 11:46:30 AM UTC-5, Antoine Jacoutot wrote:
>
> Hi.
>
> After a lot of reading about variable inheritance in ansible, there's 
> still something I cannot properly grasp...
> I hope some folks in here could enlighten me :-)
>
> So. I have a "foobar" role with some default variables set under 
> defaults/main.yml.
> So far, so good.
> But I would like some of these default variables to be for e.g. 
> OS-dependant.
> I can easily achieve that using vars or with_first_found along with 
> ansible_os_family.
> But if I do that, then I am not able to override these variables using 
> group_vars (/etc/ansible/group_vars/mygroup (like I am able to override the 
> variables set in defaults/main.yml). I do not want to have to pass 
> variables directly in the inventory file.
>
> I am sure I am missing something stupid...
> Thanks in advance.
>
> -- 
> Antoine
>

-- 
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/7016e85f-3090-4985-82e6-ed538434a2de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to