# group\_vars behavior changed in 2.1?

**URL:** <https://forum.ansible.com/t/group-vars-behavior-changed-in-2-1/22311>\
**Category:** Ansible Project\
**Created:** [August 18, 2016, 12:27am UTC](https://forum.ansible.com/t/group-vars-behavior-changed-in-2-1/22311 "2016-08-18T00:27:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent\_Jorgensen](https://avatars.discourse-cdn.com/v4/letter/v/e5b9ba/32.png) [@Vincent\_Jorgensen](https://forum.ansible.com/u/Vincent_Jorgensen)\
**Post date:** [August 18, 2016, 12:27am UTC](https://forum.ansible.com/t/group-vars-behavior-changed-in-2-1/22311/1 "2016-08-18T00:27:28Z")

</div>

Hi all, I have an ansible project with a groups\_vars directory, with a subdirectory called all beneath it, like so:  
/project/group\_vars/all/ami.yml  
/project/group\_vars/all/dns.yml

/project/group\_vars/all/key.yml

Previously, I didn’t have to specify in my playbook the path to each variable file (amis dns and keys change often enough that it’s handy to keep them separate). But since moving to 2.1.1.0, ansible can’t find the files under all, so I’ve had to resort to this:  
`

- hosts: localhost  
…  
vars\_files:
- “{{ base\_dir }}/group\_vars/all/dns.yml”
- “{{ base\_dir }}/group\_vars/all/ami.yml”
- “{{ base\_dir }}/group\_vars/all/key.yml”  
tasks:
- …

`

Did this feature go away? It isn’t the end of the world, but I liked that feature, that all could be directory or a file. Thanks. \V

---

<div class="post-metadata">

**Author:** ![David\_Resnick](https://avatars.discourse-cdn.com/v4/letter/d/838e76/32.png) [@David\_Resnick](https://forum.ansible.com/u/David_Resnick)\
**Post date:** [August 22, 2016, 3:54pm UTC](https://forum.ansible.com/t/group-vars-behavior-changed-in-2-1/22311/2 "2016-08-22T15:54:19Z")

</div>

I just posted about this too, it looks like a bug to me.

- David

---

<div class="post-metadata">

**Author:** ![Allen\_Sanabria1](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Allen\_Sanabria1](https://forum.ansible.com/u/Allen_Sanabria1)\
**Post date:** [August 22, 2016, 5:53pm UTC](https://forum.ansible.com/t/group-vars-behavior-changed-in-2-1/22311/3 "2016-08-22T17:53:05Z")

</div>

I ran into this issue as well. I decided to write an action plugin called include\_vars\_dir. This will sort the files in alphabetical order and include them. This also works in a role as well. I am in the process of writing a test suite, before making the PR. If you are interested in checking the code before the PR is made [https://github.com/linuxdynasty/ld-ansible-plugins/blob/master/action\_plugins/include\_vars\_dir.py](https://github.com/linuxdynasty/ld-ansible-plugins/blob/master/action_plugins/include_vars_dir.py)

I know some of this functionality is possible with using fileglob and include\_vars. I needed something that I can control the depth of the directory as well.

`

- name: include all yml files in group\_vars/all and all nested directories  
include\_vars\_dir:  
dir: ‘group\_vars/all’

- name: include all yml files in group\_vars/services  
include\_vars\_dir:  
dir: ‘group\_vars/services’  
depth: 1

- name: include only bastion.yml files  
include\_vars\_dir:  
dir: ‘vars’  
files\_matching: ‘bastion.yml’

- name: include only all yml files exception bastion.yml  
include\_vars\_dir:  
dir: ‘vars’  
ignore\_files: ‘bastion.yml’

`

that instead of using include\_vars with fileglob.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [August 23, 2016, 1:34pm UTC](https://forum.ansible.com/t/group-vars-behavior-changed-in-2-1/22311/4 "2016-08-23T13:34:37Z")

</div>

Ansible has no concept of ‘project’, group/host\_vars MUST be adjacent to either inventory or the play and should be picked up automatically if they match an group or host from inventory.

The vars\_files will look for relative paths in a ‘vars/’ directory adjacent to play or relative to the play, vars\_files does not look into group/host\_vars.

---

<div class="post-metadata">

**Author:** ![David\_Resnick](https://avatars.discourse-cdn.com/v4/letter/d/838e76/32.png) [@David\_Resnick](https://forum.ansible.com/u/David_Resnick)\
**Post date:** [August 24, 2016, 4:37am UTC](https://forum.ansible.com/t/group-vars-behavior-changed-in-2-1/22311/5 "2016-08-24T04:37:10Z")

</div>

Is it possible that previously Ansible looked for group\_vars in the current directory (i.e. a sub-directory of the current one)?

Because of multiple inventory files, I put inventory files in a sub-directory; in this structure:

project/  
├── group\_vars/  
│ └── all.yml  
├── playbooks/  
│ └── deploy.yml  
└── inventory/  
├── staging  
└── production

I run like this

project$ ansible-playbook -i inventory/staging playbooks/deploy.yml

In 2.1.0 variables defined in group\_vars were picked up; in 2.1.1 they are not.

Is there any way to configure a “group\_vars path” to allow using this structure in 2.1.1? From your previous answer, I’m guessing there isn’t.

- David

---

<div class="post-metadata">

**Author:** ![David\_Resnick](https://avatars.discourse-cdn.com/v4/letter/d/838e76/32.png) [@David\_Resnick](https://forum.ansible.com/u/David_Resnick)\
**Post date:** [August 24, 2016, 5:07am UTC](https://forum.ansible.com/t/group-vars-behavior-changed-in-2-1/22311/6 "2016-08-24T05:07:19Z")

</div>

OK, I see that this behavior change is being shown as a bug fix in 2.1.2:

> - Fixed a bug where a group\_vars or host\_vars directory in the current working directory would be used (and would take precedence) over those in the inventory and/or playbook directory.

It would be nice if the group\_vars directory in the current working directory was used as before.

- David
