I also have the need to set environment specific role defaults. I am using include_vars for this purpose which works fine as long as you don't want to overwrite some of this role default variables via host_vars. Because that is not going to work, because host_vars are overwritten by included vars.
Therefore after the include_vars for my role defaults, I include the hostvars explicitly again like this: - name: Include hostname specific vars include_vars: file: "host_vars/{{ inventory_hostname }}.yml" It works, but I am not sure if this is only working by accident. Regrads Daniel Am Mittwoch, 30. April 2014 22:41:29 UTC+2 schrieb Michael DeHaan: > > Well, sort of, but unfortunately, no :) > > While the default does control what variable gets loaded with "set_fact" > (this could have been done without the default) it is still going to get > loaded at a level that is not the same as defaults, so inventory can't > override what you have loaded there. > > I'd find "include_vars" cleaner personally, if that's all you want > > - include_vars: "{{ ansible_os_distribution }}.yml" > > Which allows vars/RedHat.yml and vars/Debian.yml in the role. > > > > > On Wed, Apr 30, 2014 at 5:54 AM, "F.L. Jonathan AraƱa Cruz" < > jonh...@faita.net <javascript:>> wrote: > >> On 28/04/14 23:01, Matt Willsher wrote: >> >> Hi, >> >> I'm trying to write generic roles for particular applications and keep >> hitting across the same problem: >> >> I want to set role default based on the operating system or other facts, >> like include_vars, but this doesn't appear to be supported. >> >> The only option I see practically available for template is to use the >> template logic to handle defaults, but that, while flexible, is not as >> elegant as being able to set by-fact defaults. >> >> The code I'm working at present on is >> https://github.com/WillsherPartners/ansible-sshd , where there is a >> large set of defaults and a template. sshd_subsystem_sftp varies depending >> on OS, but I still want to give the person using the role to option to >> override the value if they see fit. >> >> Are there any plans for include_vars: (include_defaults?) functionality >> in Ansible, or is there some other way to tackle per-os defaults? >> >> >> I asked for this a few weeks back. Finally I managed to implement a >> pattern in my role to workaround this >> >> https://github.com/ansible/ansible/issues/6756 >> >> >> >> >> Thanks, >> Matt >> >> >> -- >> 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-proje...@googlegroups.com <javascript:>. >> To post to this group, send email to ansible...@googlegroups.com >> <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/afaeac27-07cf-4e10-8504-ade22c361540%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ansible-project/afaeac27-07cf-4e10-8504-ade22c361540%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> >> >> -- >> 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-proje...@googlegroups.com <javascript:>. >> To post to this group, send email to ansible...@googlegroups.com >> <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/5360C83C.9080907%40faita.net >> >> <https://groups.google.com/d/msgid/ansible-project/5360C83C.9080907%40faita.net?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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/3fc66599-8d96-40da-be0f-4fd74b29568e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.