# error with vars\_files

**URL:** <https://forum.ansible.com/t/error-with-vars-files/14433>\
**Category:** Ansible Project\
**Created:** [January 27, 2014, 8:43am UTC](https://forum.ansible.com/t/error-with-vars-files/14433 "2014-01-27T08:43:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nORKy](https://avatars.discourse-cdn.com/v4/letter/n/ea666f/32.png) [@nORKy](https://forum.ansible.com/u/nORKy)\
**Post date:** [January 27, 2014, 8:43am UTC](https://forum.ansible.com/t/error-with-vars-files/14433/1 "2014-01-27T08:43:24Z")

</div>

Hi,

I start a playbook like this : ansible-playbook ./srweb.yml -K -i ./clients/Myclient -e “client=Myclient”

In my playbook, I have a vars\_files :

> vars\_files:

> - “/home/me/ansible/clients/{{ client }}.{{ ansible\_hostname }}.users”

My vars\_file start like this :

> * * *

> users:

> - login: goliath

> […]

But, there is an error :

> fatal: [srweb03] =\> One or more undefined variables: ‘str object’ has no attribute ‘login’

The task :

> - name: zfs create user base directory

> zfs: name=“{{ zbaseroot }}{{ homeprefix }}/{{ item.login }}” state=present

> with\_items: users

I checked the file"/home/me/ansible/clients/{{ client }}.{{ ansible\_hostname }}.users" with a debug task. All variables are OK and I can read the file

Where is the problem ? Thanks you

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [January 27, 2014, 12:17pm UTC](https://forum.ansible.com/t/error-with-vars-files/14433/2 "2014-01-27T12:17:11Z")

</div>

includes happen before fact gathering so ansible\_hostname is not available for use on an include.

---

<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:** [January 27, 2014, 12:44pm UTC](https://forum.ansible.com/t/error-with-vars-files/14433/3 "2014-01-27T12:44:47Z")

</div>

Hi Brian,

For once, perhaps the first time ever, that’s not it 🙂

vars\_files get evaluated in two stages.

(A) Ones that can be loaded globally, that don’t reference inventory scoped information such as facts  
(B) Ones that do.

So yes, you can use facts in vars\_files paths.

In the above example, the problem is actually that users is an array, so:

users[0].login

And it can be fixed like:

users:  
login: foo

Instead of

users:

- login: foo

🙂

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [January 27, 2014, 12:46pm UTC](https://forum.ansible.com/t/error-with-vars-files/14433/4 "2014-01-27T12:46:21Z")

</div>

sorry, i didn't even realize it is vars\_files and not 'include', just force  
of habit i guess.

---

<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:** [January 27, 2014, 12:46pm UTC](https://forum.ansible.com/t/error-with-vars-files/14433/5 "2014-01-27T12:46:29Z")

</div>

Also, I’m probably wrong here too, as the loop looks ok 🙂

---

<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:** [January 27, 2014, 12:46pm UTC](https://forum.ansible.com/t/error-with-vars-files/14433/6 "2014-01-27T12:46:49Z")

</div>

Could gather\_facts be turned off?

That would do it.

---

<div class="post-metadata">

**Author:** ![nORKy](https://avatars.discourse-cdn.com/v4/letter/n/ea666f/32.png) [@nORKy](https://forum.ansible.com/u/nORKy)\
**Post date:** [January 28, 2014, 7:55am UTC](https://forum.ansible.com/t/error-with-vars-files/14433/7 "2014-01-28T07:55:23Z")

</div>

it changes nothing if I set ‘gather\_facts’ to false. Same error

---

<div class="post-metadata">

**Author:** ![nORKy](https://avatars.discourse-cdn.com/v4/letter/n/ea666f/32.png) [@nORKy](https://forum.ansible.com/u/nORKy)\
**Post date:** [January 28, 2014, 8:09am UTC](https://forum.ansible.com/t/error-with-vars-files/14433/8 "2014-01-28T08:09:45Z")

</div>

I did a debug test:

> ok: [srweb03] =\> (item=users) =\> {  
> “item”: “users”,  
> “msg”: “the value in variable is users”  
> }

hmm… users is a string ! why ??

---

<div class="post-metadata">

**Author:** ![nORKy](https://avatars.discourse-cdn.com/v4/letter/n/ea666f/32.png) [@nORKy](https://forum.ansible.com/u/nORKy)\
**Post date:** [January 29, 2014, 1:33pm UTC](https://forum.ansible.com/t/error-with-vars-files/14433/9 "2014-01-29T13:33:23Z")

</div>

I think I found the bug  
I said in my first post that my command line to start is :

> ansible-playbook ./srweb.yml -K -i ./clients/Myclient -e “client=Myclient”

I try to set myself this var in my playbook :

> * * *
> 
> - hosts: “{{client}}-srweb” \<---- not here  
> sudo: yes  
> vars:  
> unix\_group: users  
> vars\_files:
> - “clients/Myclient.{{ ansible\_hostname }}.users” \<----- here  
> roles:
> - srweb

And it works !  
So, there is bug in the “vars\_files” option (the first line host: “{{client}}-srweb” is working)

What do you think ?
