# Parameterize an array for vars\_files, can't seem to template i.e. lookup/split

**URL:** <https://forum.ansible.com/t/parameterize-an-array-for-vars-files-cant-seem-to-template-i-e-lookup-split/28554>\
**Category:** Ansible Project\
**Created:** [September 11, 2018, 9:40pm UTC](https://forum.ansible.com/t/parameterize-an-array-for-vars-files-cant-seem-to-template-i-e-lookup-split/28554 "2018-09-11T21:40:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![H\_Kim](https://avatars.discourse-cdn.com/v4/letter/h/58956e/32.png) [@H\_Kim](https://forum.ansible.com/u/H_Kim)\
**Post date:** [September 11, 2018, 9:40pm UTC](https://forum.ansible.com/t/parameterize-an-array-for-vars-files-cant-seem-to-template-i-e-lookup-split/28554/1 "2018-09-11T21:40:12Z")

</div>

**I’d like to read in a directory full of var files without having to specify individual files.**

**The below combination of lookup and split is valid to define a variable but appears not to be supported with vars\_files with**  **“ERROR! vars file { was not found on the Ansible Controller.”**

**vars\_files:** **“{{ lookup(‘fileglob’, ‘mydir/vars/\*.yml’).split(‘,’)}}”**

---

<div class="post-metadata">

**Author:** ![H\_Kim](https://avatars.discourse-cdn.com/v4/letter/h/58956e/32.png) [@H\_Kim](https://forum.ansible.com/u/H_Kim)\
**Post date:** [September 12, 2018, 2:52am UTC](https://forum.ansible.com/t/parameterize-an-array-for-vars-files-cant-seem-to-template-i-e-lookup-split/28554/2 "2018-09-12T02:52:03Z")

</div>

I see in manager.py that the template is applied only individually per vars\_files item and not at the top level so it’s not possible to assign a list structure directly to **vars\_files.**

[https://github.com/maxamillion/ansible/blob/stable-2.6/lib/ansible/vars/manager.py](https://github.com/maxamillion/ansible/blob/stable-2.6/lib/ansible/vars/manager.py)

Any other alternatives to parameterize reading in multiple var files without having to specify the individual files would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 12, 2018, 8:51am UTC](https://forum.ansible.com/t/parameterize-an-array-for-vars-files-cant-seem-to-template-i-e-lookup-split/28554/3 "2018-09-12T08:51:29Z")

</div>

This with a loop  
[https://docs.ansible.com/ansible/latest/modules/include\_vars\_module.html](https://docs.ansible.com/ansible/latest/modules/include_vars_module.html)

---

<div class="post-metadata">

**Author:** ![H\_Kim](https://avatars.discourse-cdn.com/v4/letter/h/58956e/32.png) [@H\_Kim](https://forum.ansible.com/u/H_Kim)\
**Post date:** [September 12, 2018, 5:07pm UTC](https://forum.ansible.com/t/parameterize-an-array-for-vars-files-cant-seem-to-template-i-e-lookup-split/28554/4 "2018-09-12T17:07:57Z")

</div>

Thank you for a quick response Kai. For various reasons, we require the variables early on before the tasks stage and can’t take advantage of the wonderfully flexible include\_vars.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 12, 2018, 5:42pm UTC](https://forum.ansible.com/t/parameterize-an-array-for-vars-files-cant-seem-to-template-i-e-lookup-split/28554/5 "2018-09-12T17:42:23Z")

</div>

Even before pre\_tasks that is run before roles?

---

<div class="post-metadata">

**Author:** ![Steffen\_Becker](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@Steffen\_Becker](https://forum.ansible.com/u/Steffen_Becker)\
**Post date:** [September 13, 2018, 9:38am UTC](https://forum.ansible.com/t/parameterize-an-array-for-vars-files-cant-seem-to-template-i-e-lookup-split/28554/6 "2018-09-13T09:38:23Z")

</div>

Hi, I’ll answer this question:  
Yes, we need it for the hosts definition:

hosts: “{{ some\_var\_from\_some\_of\_the\_var\_files }}”

---

<div class="post-metadata">

**Author:** ![powcarz](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@powcarz](https://forum.ansible.com/u/powcarz)\
**Post date:** [November 28, 2018, 11:42am UTC](https://forum.ansible.com/t/parameterize-an-array-for-vars-files-cant-seem-to-template-i-e-lookup-split/28554/7 "2018-11-28T11:42:55Z")

</div>

Hi all

I have the very same issue, trying to include a pattern of files. I was also expecting the following to work

`vars_files: "{{ query('fileglob', 'mydir/vars/want_these_*.yml')}}"`

but I am getting the same error. Did you manage to find a workaround?

For me the include\_vars module is not an option, since I also need to evaluate the “{{…}}” inside the included files. Unfortunately, there is no import\_vars module…  
I will be also grateful for any tips. My ultimate goal is load variables from a bunch of files using glob or regex pattern, and evaluate {{}} inside them.
