Hi all,
I’d like to use the “Sourced from a Project” feature of the inventories but I’ve found that it doesn’t import any of my host_vars or group_vars with my project set up as it is:
project/ group_vars/ dev.yml host_vars/ hostname.yml inventories/ dev.ini
This was logged here but was regarding Tower rather than awx so was closed. Is there a certain way you have to layout the project to get this to work or is it just unsupported at the moment?
Using awx 1.0.2 commit ae06cff and awx_web/awx_task 1.0.2.337
Thanks,
Bobby
Hi Bobby,
In your case, it looks like group_vars and host_vars are adjacent to the project but not to the inventory file. If you want those variables imported, you would need to either:
-
move group_vars/host_vars inside the inventories directory and specify the dev.ini file as your inventory source
-
specify the inventories directory as your inventory source (though AWX doesn’t currently appear to detect a directory as a possible inventory source).
In their current location, group_vars/host_vars still work if you run ansible directory, because ansible itself loads group/host variables from the inventory as well as the project (see http://docs.ansible.com/ansible/latest/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable).
You can run either of the following to see which variables AWX should import for a given inventory source:
- ansible-inventory -i inventories --list
- ansible-inventory -i inventories/dev.ini --list
Hi Chris,
I moved both group_vars/ and host_vars/ into inventories/ and awx is now picking up the host_vars but still not the group_vars. Here’s how it’s currently set up (using one dev host as an example):
project/ inventories/ group_vars/ dev.yml host_vars/ hostname.yml dev.ini
dev.ini:
`
[loader]
hostname
[dev:children]
loader
`
I ran the ansible-inventory -i inventories/dev.ini --list command and it does display all group_vars and host_vars but AWX doesn’t pull them in.
Actually there’s something much weirder going on here. Will test and raise a bug on GitHub and post link here.
AWX relies on ansible-inventory to generate inventory. ansible-inventory, currently, applies group_vars to the respective hosts and only outputs host_vars. Example behavior https://github.com/chrismeyersfsu/ansible-examples/tree/master/ansible-inventory
If you run the make target in there with ansible 2.4.2.x you get the following:
ansible-inventory -i inventory --list
{
“_meta”: {
“hostvars”: {
“starscream”: {
“i_am_a_decepticon_group_variable”: “i_am_a_decepticon_group_variable_value”,
“i_am_a_starscream_host_variable”: “i_am_a_starscream_host_variable_value”,
“i_am_an_explicit_inventory_host_variable”: “i_am_an_explicit_inventory_host_variable_value”
}
}
},
“all”: {
“children”: [
“decepticons”,
“ungrouped”
]
},
“decepticons”: {
“hosts”: [
“starscream”
]
},
“ungrouped”: {}
}
where i_am_a_decepticon_group_variable is a groups variable, but, as you can see from the above, it is applied to the hostvars section. I’m checking with ansible core to see about changing ansible-inventory to allow for a flag to NOT apply group vars to host vars.