Ansible Role Variables as Defaults

22 views
Skip to first unread message

Sam Darwin

unread,
Jun 14, 2017, 7:43:11 AM6/14/17
to Ansible Project
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: 


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.

Reply all
Reply to author
Forward
0 new messages