# Ansible Role Variables as Defaults

**URL:** <https://forum.ansible.com/t/ansible-role-variables-as-defaults/24725>\
**Category:** Ansible Project\
**Created:** [June 14, 2017, 11:43am UTC](https://forum.ansible.com/t/ansible-role-variables-as-defaults/24725 "2017-06-14T11:43:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdarwin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sdarwin/32/2450_2.png) [@sdarwin](https://forum.ansible.com/u/sdarwin)\
**Post date:** [June 14, 2017, 11:43am UTC](https://forum.ansible.com/t/ansible-role-variables-as-defaults/24725/1 "2017-06-14T11:43:11Z")

</div>

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/](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.
