Ansible Role Variables as Defaults

Hi,

A problem I have often encountered when writing Ansible Roles is that the precedence level of “vars” prevents overriding them - in group_vars, inventory, etc.

Perhaps this can be a solution, a set_fact task which converts selected Role Variables into Default Variables:

https://www.samdarwin.com/ansible-default-vars/

Let me know your feedback or if you see any technical problems. Hopefully this will be useful for everyone who is composing Ansible Roles.

You might propose that if a role variable is going to be overridden, then it should just be set as a “default” in role/defaults/main.yml. Yes, that is fine for many common situations. However, include_vars does not work for defaults, only vars. There is no include_defaults. And why do you need that? It would allow for conditional logic such as per operating system settings.