# roles/vars/main.yml - but what about other files in this directory

**URL:** <https://forum.ansible.com/t/roles-vars-main-yml-but-what-about-other-files-in-this-directory/12838>\
**Category:** Ansible Project\
**Created:** [May 21, 2013, 12:31pm UTC](https://forum.ansible.com/t/roles-vars-main-yml-but-what-about-other-files-in-this-directory/12838 "2013-05-21T12:31:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jschulman](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jschulman](https://forum.ansible.com/u/jschulman)\
**Post date:** [May 21, 2013, 12:31pm UTC](https://forum.ansible.com/t/roles-vars-main-yml-but-what-about-other-files-in-this-directory/12838/1 "2013-05-21T12:31:31Z")

</div>

I’m using roles for template building, and would like to understand the use the of the vars directory a bit more. From the docs, I see that ansible will automatically pick up roles/{role}/vars/main.yml. But let’s say that I want to put multiple var files in the vars directory. Is there a way to tell ansible to pickup not only main.yml, but every other \*.yml file in that directory as well?

Thank you!

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [May 21, 2013, 12:48pm UTC](https://forum.ansible.com/t/roles-vars-main-yml-but-what-about-other-files-in-this-directory/12838/2 "2013-05-21T12:48:57Z")

</div>

Could you try this for now

in main.yml  
var\_files:

- “…/var1.yml”

Also i guess a feature request has been made for automatic inclusion of all vars file, so down the line this should work without manual inclusion.

- Benno

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 21, 2013, 12:50pm UTC](https://forum.ansible.com/t/roles-vars-main-yml-but-what-about-other-files-in-this-directory/12838/3 "2013-05-21T12:50:56Z")

</div>

Yep, this was already requested yesterday:

[https://github.com/ansible/ansible/issues/2958](https://github.com/ansible/ansible/issues/2958)

---

<div class="post-metadata">

**Author:** ![jschulman](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jschulman](https://forum.ansible.com/u/jschulman)\
**Post date:** [May 21, 2013, 1:04pm UTC](https://forum.ansible.com/t/roles-vars-main-yml-but-what-about-other-files-in-this-directory/12838/4 "2013-05-21T13:04:55Z")

</div>

Thank you, but this does not seem to be working. Are you sure it’s “var\_files” and not “vars\_files”? I’ve tried a number of options, with and without quotes around the filename, but no luck.

I do appreciate your help, thank you again!

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [May 21, 2013, 1:45pm UTC](https://forum.ansible.com/t/roles-vars-main-yml-but-what-about-other-files-in-this-directory/12838/5 "2013-05-21T13:45:37Z")

</div>

Actually i meant vars\_files: but i guess even that doesn’t seem to work in vars/main.yml, so i guess the only option might be to include it in your main playbook. but i will wait for others to also comment.

Thanks,  
Benno

---

<div class="post-metadata">

**Author:** ![jschulman](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jschulman](https://forum.ansible.com/u/jschulman)\
**Post date:** [May 21, 2013, 2:13pm UTC](https://forum.ansible.com/t/roles-vars-main-yml-but-what-about-other-files-in-this-directory/12838/6 "2013-05-21T14:13:42Z")

</div>

Hi Benno,

Thank you for the clarification. I was thinking (hoping) that “vars\_files” would work inside main.yml.

Do you know when ansible will support reading all .yml files from within the roles/…/vars directory?

Thank you!  
– Jeremy

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 21, 2013, 2:28pm UTC](https://forum.ansible.com/t/roles-vars-main-yml-but-what-about-other-files-in-this-directory/12838/7 "2013-05-21T14:28:43Z")

</div>

Variable files can’t do includes, no.

vars\_files is the way to go.

---

<div class="post-metadata">

**Author:** ![Renaud\_Guerin](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@Renaud\_Guerin](https://forum.ansible.com/u/Renaud_Guerin)\
**Post date:** [July 2, 2014, 4:10pm UTC](https://forum.ansible.com/t/roles-vars-main-yml-but-what-about-other-files-in-this-directory/12838/8 "2014-07-02T16:10:16Z")

</div>

Hi Michael,

Has this ever been implemented ?

With Vault especially, it seems like a sensible pattern to have a separate encrypted file in vars/ for credentials, next to main.yml

Having to specify include\_vars or vars\_files explicitly each time feels a little clumsy : shouldn’t one reasonably expect a directory named “vars” to have some magic meaning and consider all of its contents automatically (like group\_vars and inventory directories do) ?

Since vars/ also doesn’t serve as a default path for include\_vars in role tasks (AFAIK, you have to explicitly say “…/vars/xxx.yml”), technically it might as well be just “roles/x/vars.yml”, right ?

---

<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:** [July 2, 2014, 10:16pm UTC](https://forum.ansible.com/t/roles-vars-main-yml-but-what-about-other-files-in-this-directory/12838/9 "2014-07-02T22:16:27Z")

</div>

“Has this ever been implemented?”

Vault yes, the feature about multiple files in vars/ automatically being loaded? No.

Files in vars/ are not all automatically loaded - it would absolutely break certain classes of playbooks, so we can’t/won’t go there.

include\_vars is a good solution from the task file for specific files.
