# How do I load a specific var file for a role in the most elegant way?

**URL:** <https://forum.ansible.com/t/how-do-i-load-a-specific-var-file-for-a-role-in-the-most-elegant-way/15575>\
**Category:** Ansible Project\
**Created:** [June 30, 2014, 8:20am UTC](https://forum.ansible.com/t/how-do-i-load-a-specific-var-file-for-a-role-in-the-most-elegant-way/15575 "2014-06-30T08:20:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uri\_Miller](https://avatars.discourse-cdn.com/v4/letter/u/e99b99/32.png) [@Uri\_Miller](https://forum.ansible.com/u/Uri_Miller)\
**Post date:** [June 30, 2014, 8:20am UTC](https://forum.ansible.com/t/how-do-i-load-a-specific-var-file-for-a-role-in-the-most-elegant-way/15575/1 "2014-06-30T08:20:23Z")

</div>

I have tried _include\_vars_ and _vars\_files_ but maybe in the wrong context, because it doesn’t seem to work although i did not receive an error from Ansible:

I have tried these two options, both did not seem to work:

**option 1:**

---

<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:** [June 30, 2014, 1:55pm UTC](https://forum.ansible.com/t/how-do-i-load-a-specific-var-file-for-a-role-in-the-most-elegant-way/15575/2 "2014-06-30T13:55:01Z")

</div>

Please reference the ansible documentation for how include\_vars and vars\_files work.

Using a variable name passed to a role is not one of those examples 🙂

---

<div class="post-metadata">

**Author:** ![Uri\_Miller](https://avatars.discourse-cdn.com/v4/letter/u/e99b99/32.png) [@Uri\_Miller](https://forum.ansible.com/u/Uri_Miller)\
**Post date:** [June 30, 2014, 2:07pm UTC](https://forum.ansible.com/t/how-do-i-load-a-specific-var-file-for-a-role-in-the-most-elegant-way/15575/3 "2014-06-30T14:07:20Z")

</div>

Thanks Michael, I have figured that out,  
But what is Ansible way to load var file for a role?  
I would like to execute the same role, each time with a different var file. (The motivation is override)

---

<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:** [June 30, 2014, 2:24pm UTC](https://forum.ansible.com/t/how-do-i-load-a-specific-var-file-for-a-role-in-the-most-elegant-way/15575/4 "2014-06-30T14:24:53Z")

</div>

You could use include\_vars as a module call from the tasks file if you wanted to do this, and pass in the variable name of the file to load, possibly setting it in defaults.

Though a more frequently used technique would be set values in roles/foo/defaults.yml and pass in override values directly to the role.
