# Trying to dynamically load var files

**URL:** <https://forum.ansible.com/t/trying-to-dynamically-load-var-files/20711>\
**Category:** Ansible Project\
**Created:** [February 29, 2016, 11:47pm UTC](https://forum.ansible.com/t/trying-to-dynamically-load-var-files/20711 "2016-02-29T23:47:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris5](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@Chris5](https://forum.ansible.com/u/Chris5)\
**Post date:** [February 29, 2016, 11:47pm UTC](https://forum.ansible.com/t/trying-to-dynamically-load-var-files/20711/1 "2016-02-29T23:47:56Z")

</div>

I’m not seeing a clear way on how to do this in the docs, and maybe there is some other way to go about it. Basically I want to load up data about multiple applications to use in a template. I tried using include\_vars, but I’m not seeing how to dynamically load that. I currently have this structure:

groups\_vars/staging\_apps.yml:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 1, 2016, 5:22am UTC](https://forum.ansible.com/t/trying-to-dynamically-load-var-files/20711/2 "2016-03-01T05:22:39Z")

</div>

first, don’t put anything under group\_vars/host\_vars that you want to selectively load, these files will load automatically if matched. Using include\_vars against group/host\_vars is not recommended.

2nd the easiest way is putting them in a vars/ folder adjacent to play (or in role) and use include\_vars:

- include\_vars: “{{item}}.yml”  
with\_items: “{{apps}}”

if what you want it to load both files with last one overriding previous ones when the same vars are in multiple files.

---

<div class="post-metadata">

**Author:** ![Chris5](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@Chris5](https://forum.ansible.com/u/Chris5)\
**Post date:** [March 1, 2016, 5:03pm UTC](https://forum.ansible.com/t/trying-to-dynamically-load-var-files/20711/3 "2016-03-01T17:03:16Z")

</div>

That’s what I needed, thanks!!
