# Discrepancy between \`vars\_files\` and \`include\_vars\`

**URL:** <https://forum.ansible.com/t/discrepancy-between-vars-files-and-include-vars/14447>\
**Category:** Ansible Project\
**Created:** [January 29, 2014, 12:29am UTC](https://forum.ansible.com/t/discrepancy-between-vars-files-and-include-vars/14447 "2014-01-29T00:29:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Porter](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@Michael\_Porter](https://forum.ansible.com/u/Michael_Porter)\
**Post date:** [January 29, 2014, 12:29am UTC](https://forum.ansible.com/t/discrepancy-between-vars-files-and-include-vars/14447/1 "2014-01-29T00:29:21Z")

</div>

I recently came across `include_vars` as a method of allowing roles to load variables files based on facts, etc. However, I’m encountering an odd combination of issues in trying to structure my variables in a way that allows for proper overloading and (if possible) merging.

I notice that I can make use of `with_first_found` in conjunction with `include_vars` in my role’s task file(s) to fallback to sane defaults, eg.:

- name: Include base yum repos  
include\_vars: “{{ item }}”  
with\_first\_found:

- “…/vars/yum/{{ ansible\_lsb.id|lower }}\_{{ ansible\_lsb.major\_release }}.yml”

- “…/vars/yum/{{ ansible\_lsb.id|lower }}.yml”

- “…/vars/yum/unknown.yml”

(as an aside, the requirement to provide a relative path, as it’s implemented via a lookup plugin seems to be obtuse and counter-intuitive, by the way, when compared to the way the path is properly resolved within the role’s vars/ directory with a single path, eg. “include\_vars: ‘yum/centos.yml’”)

However, it would be nice to be able to merge in an additional default for all cases in a manner similar to what’s done for `vars_files` in a playbook:

- name: Include base yum repos  
include\_vars:
- “yum/default.yml”
- [“yum/{{ ansible\_lsb.id|lower }}\_{{ ansible\_lsb.major\_release }}.yml”, “yum/{{ ansible\_lsb.id|lower }}.yml”, “yum/unknown.yml”]

Working similarly to `vars_files`, this would treat an element with a list type as a first-found declaration.

I’m certain that there’s a purpose behind the implementation, so I’m curious what the reasons are behind the implementation and what gotchas would likely be lurking behind. I’ve already noticed that hashes aren’t merged (even with `hash_behaviour` set to “merge” in the ansible.cfg) when attempting to work around this with multiple `include_vars` actions:

- name: Include default yum repos  
include\_vars: “yum/default.yml”
- name: Include base yum repos

include\_vars: “{{ item }}”  
with\_first\_found:

- “…/vars/yum/{{ ansible\_lsb.id|lower }}\_{{ ansible\_lsb.major\_release }}.yml”

- “…/vars/yum/{{ ansible\_lsb.id|lower }}.yml”

- “…/vars/yum/unknown.yml”

I’d gladly offer pull requests to perhaps make this more intuitive or consistent, if I could better understand the challenges involved in loading variables for a role this way.

Thanks!
