# vars\_files: expand list of files via a single variable

**URL:** <https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099>\
**Category:** Ansible Project\
**Created:** [September 2, 2014, 3:05pm UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099 "2014-09-02T15:05:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [September 2, 2014, 3:05pm UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099/1 "2014-09-02T15:05:53Z")

</div>

So I just recently discovered how to list several possible vars\_files, with precedence, and where some may not exist:

[http://serverfault.com/questions/589734/ansible-can-i-use-vars-files-when-some-files-do-not-exist](http://serverfault.com/questions/589734/ansible-can-i-use-vars-files-when-some-files-do-not-exist)

Very handy. Where is the documentation for this?

Next question…

I’d like to centralise a list of possible vars\_files in a single variable but can’t get it to work. E.g:

`

vars\_files:

- [“{{ settings\_files }}”]

`

and then in say group\_vars/all I have my files defined:

`

settings\_files: ‘“…/settings.yml”, “…/example.settings.yml”’

`

But that doesn’t work - I get the following error:

`

vlad: not importing file: /Volumes/Data/Projects/vlad/vlad/vlad/playbooks/“…/settings.yml”, “…/example.settings.yml”  
ERROR: vlad: FATAL, no files matched for vars\_files import sequence: [u’/Volumes/Data/Projects/vlad/vlad/vlad/playbooks/“…/settings.yml”, “…/example.settings.yml”']

`

It looks like something is happening on expansion that I wasn’t expecting.

I’m hoping this is just a question of syntax and I’ve messed around with a few variations but am still having no luck.

Can anyone help with this? Is it even possible?

I’m running Ansible v1.7.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:** [September 2, 2014, 10:45pm UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099/2 "2014-09-02T22:45:45Z")

</div>

What were you expecting?

It’s saying none of the files in the list were found and hitting an error condition, but I’m unclear which parts you find unusual.

Thanks!

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [September 3, 2014, 6:24am UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099/3 "2014-09-03T06:24:02Z")

</div>

Michael DeHaan \<michael@ansible.com\> napisał:

> What were you expecting?
> 
> It's saying none of the files in the list were found and hitting an  
> error  
> condition, but I'm unclear which parts you find unusual.

The path in the error looks strange 😉

> > So I just recently discovered how to list several possible
> 
> vars\_files,
> 
> > with precedence, and where some may not exist:
> 
> [http://serverfault.com/questions/589734/ansible-can-i-use-vars-files-when-some-files-do-not-exist](http://serverfault.com/questions/589734/ansible-can-i-use-vars-files-when-some-files-do-not-exist)
> 
> > Very handy. Where is the documentation for this?
> > 
> > Next question...
> > 
> > I'd like to centralise a list of possible vars\_files in a single
> 
> variable
> 
> > but can't get it to work. E.g:
> > 
> > vars\_files:  
> > &nbsp;&nbsp;- ["{{ settings\_files }}"]
> > 
> > and then in say group\_vars/all I have my files defined:
> > 
> > settings\_files: '"../settings.yml", "../example.settings.yml"'

I think you want to create a list here, like this:

settings\_files:  
- ../settings.yml  
- ../example.settings.yml

And then use it like this:

vars\_files:  
&nbsp;&nbsp;&nbsp;- "{{ settings\_files }}"

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [September 3, 2014, 9:25am UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099/4 "2014-09-03T09:25:30Z")

</div>

As Tomasz says below, the path in the error looks strange:

`  
[u’/Volumes/Data/Projects/vlad/vlad/vlad/playbooks/“…/settings.yml”, “…/example.settings.yml”']

`

…especially when compared to the paths stored in my settings\_files variable:

`  
settings\_files: ‘“…/settings.yml”, “…/example.settings.yml”’

`

So you know, the “/Volumes/Data/Projects/vlad/vlad/vlad/playbooks/” part that’s being prepended is the path to the playbook that’s calling vars\_files.

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [September 3, 2014, 9:28am UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099/5 "2014-09-03T09:28:45Z")

</div>

Thanks for the suggestion but I already tried that and it results in a huge error:

`

Traceback (most recent call last):  
File “/usr/local/Cellar/ansible/1.7.1/libexec/bin/ansible-playbook”, line 5, in   
pkg\_resources.run\_script(‘ansible==1.7.1’, ‘ansible-playbook’)  
File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg\_resources.py”, line 489, in run\_script  
self.require(requires)[0].run\_script(script\_name, ns)  
File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg\_resources.py”, line 1207, in run\_script  
execfile(script\_filename, namespace, namespace)  
File “/usr/local/Cellar/ansible/1.7.1/lib/python2.7/site-packages/ansible-1.7.1-py2.7.egg/EGG-INFO/scripts/ansible-playbook”, line 309, in   
sys.exit(main(sys.argv[1:]))  
File “/usr/local/Cellar/ansible/1.7.1/lib/python2.7/site-packages/ansible-1.7.1-py2.7.egg/EGG-INFO/scripts/ansible-playbook”, line 249, in main  
pb.run()  
File “/usr/local/Cellar/ansible/1.7.1/lib/python2.7/site-packages/ansible-1.7.1-py2.7.egg/ansible/playbook/ **init**.py”, line 339, in run  
if not self.\_run\_play(play):  
File “/usr/local/Cellar/ansible/1.7.1/lib/python2.7/site-packages/ansible-1.7.1-py2.7.egg/ansible/playbook/ **init**.py”, line 646, in \_run\_play  
play.update\_vars\_files(all\_hosts, vault\_password=self.vault\_password)  
File “/usr/local/Cellar/ansible/1.7.1/lib/python2.7/site-packages/ansible-1.7.1-py2.7.egg/ansible/playbook/play.py”, line 698, in update\_vars\_files  
self.\_update\_vars\_files\_for\_host(h, vault\_password=vault\_password)  
File “/usr/local/Cellar/ansible/1.7.1/lib/python2.7/site-packages/ansible-1.7.1-py2.7.egg/ansible/playbook/play.py”, line 847, in \_update\_vars\_files\_for\_host  
filename2, filename3, filename4 = generate\_filenames(host, inject, filename)  
File “/usr/local/Cellar/ansible/1.7.1/lib/python2.7/site-packages/ansible-1.7.1-py2.7.egg/ansible/playbook/play.py”, line 775, in generate\_filenames  
filename4 = utils.path\_dwim(self.basedir, filename3)  
File “/usr/local/Cellar/ansible/1.7.1/lib/python2.7/site-packages/ansible-1.7.1-py2.7.egg/ansible/utils/ **init**.py”, line 318, in path\_dwim  
if given.startswith(“/”):  
AttributeError: ‘list’ object has no attribute ‘startswith’

`

I’m guessing that this is the most useful part of that error:

`  
AttributeError: ‘list’ object has no attribute ‘startswith’

`

Out of curiosity, I wrapped each path string in the list with double quotes but it results in pretty much the same thing.

---

<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:** [September 3, 2014, 11:42am UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099/6 "2014-09-03T11:42:30Z")

</div>

“settings\_files: '”…/settings.yml", “…/example.settings.yml”’

It should be noted this is not a YAML list, and that is probably part of your problem.

The path being an array of unicode elements does not look strange to me. Is there a particular path element in the list that looks strange to you?

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [September 3, 2014, 12:08pm UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099/7 "2014-09-03T12:08:01Z")

</div>

Sure. Once again for reference, here’s that path from the error message:

`  
[u’/Volumes/Data/Projects/vlad/vlad/vlad/playbooks/“…/settings.yml”, “…/example.settings.yml”']

`

Disregarding the wrapping square brackets, the wrapping single quotes and the preceding “u” gives us:

`  
/Volumes/Data/Projects/vlad/vlad/vlad/playbooks/“…/settings.yml”, “…/example.settings.yml”

`

Now look at where the first and second double quotes are. That looks funky to me.

Surely the first element in the array should be entirely wrapped in double quotes? Also, having ‘…/’ anywhere other than at the start of a path is surely going to cause problems.

It appears as if Ansible is prefixing an absolute path (the path to the playbook making the call: /Volumes/Data/Projects/vlad/vlad/vlad/playbooks/) to my expanded variable, irrespective of what my variable contains. This in turn is making the expanded variable a bit garbled, hence the error.

---

<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:** [September 3, 2014, 4:06pm UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099/8 "2014-09-03T16:06:04Z")

</div>

Yes, the quotes definitely look funky.

Thanks for bearing with me and my reading comprehension skills.

If this occurs on 1.7.1 or devel, can you file a bug on this one? This most definitely should not happen and we’ll want to correct this.

Thanks!

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [September 3, 2014, 4:11pm UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099/9 "2014-09-03T16:11:31Z")

</div>

No worries 🙂

This is with Ansible v1.7.1 so I’ll file the bug report and point back here for reference.

---

<div class="post-metadata">

**Author:** ![Dan\_Bohea](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Dan\_Bohea](https://forum.ansible.com/u/Dan_Bohea)\
**Post date:** [September 3, 2014, 5:15pm UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099/10 "2014-09-03T17:15:50Z")

</div>

Bug report: [https://github.com/ansible/ansible/issues/8881](https://github.com/ansible/ansible/issues/8881)

---

<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:** [September 5, 2014, 1:17am UTC](https://forum.ansible.com/t/vars-files-expand-list-of-files-via-a-single-variable/16099/11 "2014-09-05T01:17:26Z")

</div>

Thanks!
