You’re confusing the structure a bit.
- The
group_vars
directory contains files for each hostgroup defined in your inventory file. The files define variables that member hosts can use. - The inventory file doesn’t reside in the
group_vars
dir, it should be outside. - Only hosts that are members of a group can use its variables, so unless you put 127.0.0.1 in a group, it won’t be able to use any group_vars beside those defined in
group_vars/all
.
What you want is this dir structure:
group_vars/
all
perlservers
phl-stage
hosts
site.yml
local.yml
Your hosts file should look like this, assuming 127.0.0.1 is just a staging server and not perl or web server:
[webservers]
phl-web1
phl-web2
[perlservers]
phl-perl1
phl-perl2
[phl-stage]
127.0.0.1
[phl-stage:children]
webservers
perlservers
So you define which hosts belong to which group in the inventory, and then for each group you define variables in its group_vars file.