nORKy
(nORKy)
1
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:
[…]
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
includes happen before fact gathering so ansible_hostname is not available for use on an include.
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:
sorry, i didn't even realize it is vars_files and not 'include', just force
of habit i guess.
Also, I’m probably wrong here too, as the loop looks ok
Could gather_facts be turned off?
That would do it.
nORKy
(nORKy)
7
it changes nothing if I set ‘gather_facts’ to false. Same error
nORKy
(nORKy)
8
I did a debug test:
ok: [srweb03] => (item=users) => {
“item”: “users”,
“msg”: “the value in variable is users”
}
hmm… users is a string ! why ??
nORKy
(nORKy)
9
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 ?