# the precedence of var\_files includes when path is constructed from vars

**URL:** <https://forum.ansible.com/t/the-precedence-of-var-files-includes-when-path-is-constructed-from-vars/16620>\
**Category:** Ansible Project\
**Created:** [October 27, 2014, 6:23pm UTC](https://forum.ansible.com/t/the-precedence-of-var-files-includes-when-path-is-constructed-from-vars/16620 "2014-10-27T18:23:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@Nick](https://forum.ansible.com/u/Nick)\
**Post date:** [October 27, 2014, 6:23pm UTC](https://forum.ansible.com/t/the-precedence-of-var-files-includes-when-path-is-constructed-from-vars/16620/1 "2014-10-27T18:23:48Z")

</div>

Hello,

Something I discovered about ansible this morning surprised me. Essentially: when loading vars files, anything loaded with a \*dynamically constructed name depending on the host\* seems to be lower precedence than those files with fixed names, or even dynamic names not depending on the host. I'd have expected the opposite? (My ansible version is a recent development one, specific information appended below.)

To elaborate, I was trying to override some variables like this:

---

<div class="post-metadata">

**Author:** ![Nick](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@Nick](https://forum.ansible.com/u/Nick)\
**Post date:** [October 30, 2014, 9:13am UTC](https://forum.ansible.com/t/the-precedence-of-var-files-includes-when-path-is-constructed-from-vars/16620/2 "2014-10-30T09:13:45Z")

</div>

For the record, currently I am working around the aforementioned var precedence behaviour with a diabolical hack, as follows:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 30, 2014, 8:48pm UTC](https://forum.ansible.com/t/the-precedence-of-var-files-includes-when-path-is-constructed-from-vars/16620/3 "2014-10-30T20:48:28Z")

</div>

inventory scoped variables have less priority than globally scoped things.

This is expected, yes.

---

<div class="post-metadata">

**Author:** ![Nick](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@Nick](https://forum.ansible.com/u/Nick)\
**Post date:** [October 30, 2014, 10:07pm UTC](https://forum.ansible.com/t/the-precedence-of-var-files-includes-when-path-is-constructed-from-vars/16620/4 "2014-10-30T22:07:53Z")

</div>

Thanks for confirming. This case didn't appear to be inventory scoped, as it  
wasn't taking information from host\_vars or group\_vars, but I see why it is  
logically the same.  
Even so, the precedence seems backward: less specific globals beat more specific  
inventory vars. Is there a reason for this or is it purely historical? If you  
can tell me I'll attempt a documentation patch.

Assuming I'm not a weirdo and it is indeed a common case to want global defaults  
which can be over-ridden on specific hosts, then I don't see a way to do that at  
a playbook level rather than using role defaults or follownig the docs'  
recommendation that "Site wide defaults should be defined as a ‘group\_vars/all’  
setting". These both force me to move playbook specific information into a  
location where they lose context or may be swamped by unrelated definitions.  
Task includes and the set\_fact module might be another option, but they set vars  
at "task time", which I believe is too late for the values to be seen in roles  
the playbook might include.

Would playbook default vars be considered a reasonable feature request?

N

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [November 1, 2014, 2:45pm UTC](https://forum.ansible.com/t/the-precedence-of-var-files-includes-when-path-is-constructed-from-vars/16620/5 "2014-11-01T14:45:08Z")

</div>

I’m happy with things as documented today.

Please refer to

### [Variables — Ansible Documentation](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB4QFjAA&url=http%3A%2F%2Fdocs.ansible.com%2Fplaybooks_variables.html&ei=vvFUVIupL8WigwTrooC4Cw&usg=AFQjCNGhBjMfoMhWO21zhvtdE20FdYJVng&sig2=7rp8pjkKy9joJXTv3sOklg&bvm=bv.78677474,d.eXY)

We have several thousands of users here and can’t change behavior based on a particular request to do it differently, unfortunately.

If you want defaults, look at “defaults” in roles, which have lower power than even inventory.
