0
votes

My understanding is that group and host vars can be placed under the root ansible directory.

Based on the below, with group_vars in its location, the playbook returns an error saying it is unable to find the vars. If I move it to the inventory folder all is ok.

tree .
.
├── ansible.cfg
├── group_vars
│   └── all.yaml
├── inventory
│   ├── host_vars
│   │   ├── access1.yaml
│   │   ├── access2.yaml
│   │   └── aggr1.yaml
│   └── test
├── playbooks
│   ├── site.retry
│   └── site.yaml
└── README.md

All other guides show the host_vars/group_vars in the root location? Is there a setting I need to update or check to allow this?

EDIT: ansible.cfg is shown below:

[defaults]
gathering = explicit
Inventory = ./inventory/test
retry_files_enabled = False
Host_key_checking = false
Timeout = 5

[persistent_connection]
connect_timeout = 30
command_timeout = 30
1
Is there a reason why you're not using a single file? - Yaron
a single file for group_vars , you mean? - felix001
Nope, a single file for the entire inventory. - Yaron
because i will have different environments - felix001
What do you have configured as the inventory option of the ansible.cfg file? - guzmonne

1 Answers

0
votes

see the first tip in https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#organizing-host-and-group-variables

The group_vars/ and host_vars/ directories can exist in the playbook directory OR the inventory directory. If both paths exist, variables in the playbook directory will override variables set in the inventory directory.

So you can configure your ansible.cfg to use a inventory file in ./ then your group_vars and host_vars can exist in this directory too. Your inventory file is under the ./inventory/ directory which is not ./ .