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
I just posted about this too, it looks like a bug to me.
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
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.
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.
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.
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.