# variables in group\_vars and host\_vars do not load when using inventory directory

**URL:** <https://forum.ansible.com/t/variables-in-group-vars-and-host-vars-do-not-load-when-using-inventory-directory/28639>\
**Category:** Ansible Project\
**Created:** [September 24, 2018, 8:34pm UTC](https://forum.ansible.com/t/variables-in-group-vars-and-host-vars-do-not-load-when-using-inventory-directory/28639 "2018-09-24T20:34:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![myprogramingnotes](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@myprogramingnotes](https://forum.ansible.com/u/myprogramingnotes)\
**Post date:** [September 24, 2018, 8:34pm UTC](https://forum.ansible.com/t/variables-in-group-vars-and-host-vars-do-not-load-when-using-inventory-directory/28639/1 "2018-09-24T20:34:48Z")

</div>

A playbook I ran, returned this failure:  
`TASK [create-admin-user : Create the non-root user account] ******************** fatal: [415.791.30.131]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'admin_user' is undefined\n\nThe error appears to have been in '/Users/pnotes/Code/terraform/pj1/ansi/roles/create-admin-user/tasks/main.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Task 1\n ^ here\n"}`

Given this directory structure:  
`├── ansible.cfg ├── inventories │ └── test │ ├── group_vars │ │ └── all.yml │ ├── host_vars │ │ └── all.yml │ └── hosts.ini ├── provision.yml └── roles └── create-admin-user ├── handlers │ └── main.yml └── tasks └── main.yml`

> **Note that is directory layout follows that given in the [docs](https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html#alternative-directory-layout)**

And a role defined like this:  
`

- name: Create the non-root user account  
user:  
name: “{{ admin\_user.name }}”  
password: “{{ admin\_user.password | password\_hash(‘sha512’) }}”  
update\_password: on\_create  
group: sudo  
groups: sudo  
append: yes  
create\_home: yes  
shell: /bin/bash

`

I expect the task, **create-admin-user** , defined above to pick variables defined in _inventories/test/group\_vars/all.ym_l and _inventories/test/host\_vars/all.yml_ **but** the error messages shows that these variables aren’t.

This doesn’t make sense to me given that group\_vars && host\_vars both follow this structure:  
`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 1, 2020, 2:27pm UTC](https://forum.ansible.com/t/variables-in-group-vars-and-host-vars-do-not-load-when-using-inventory-directory/28639/2 "2020-05-01T14:27:18Z")

</div>

host\_vars/all.yml will not affect 'all hosts', just a host named  
'all'. Still the group\_vars/all.yml should work, my tests do show it  
working, can you provide more info like the full error and -vvv  
output?
