Mutliple inventories, group_vars and empty group issues

Hi there,

Got an issue with AWX 1.0.6.14 / ansible 2.5.4

First let me explain the directory and ini structure :

inventory/core/core.ini
inventory/core/group_vars/all/all.yml
inventory/core/group_vars/core/core.yml
inventory/core/group_vars/dns/dns.yml
inventory/core/host_vars/dns1
inventory/core/host_vars/dns2
inventory/dc01/dc01.ini
inventory/dc01/group_vars/dc01/dc01.yml
inventory/dynamic/dynamic.sh

The content of core.ini is to define hosts into groups that must be deployed to different locations (dc01, dc02…)

[core:children]
dns

[dns]
dns1
dns2

dc01.ini creates a mapping of core hosts to the defined dc01 group and a declaration of an empty group that is filled by the dynamic inventory script (not declaring it throws an error) :

[dc01:children]
core
products

[products]
#(empty)

Last is a dynamic inventory script that outputs a json like :

{"_meta": {"hostvars": {"product01": {"ansible_host": "10.0.1.181"}, "product02": {"ansible_host": "10.0.1.182"}}}, "products": {"hosts": ["product01", "product02"]}}

When running ansible-playbook -i inventory/core/core.ini -i inventory/dc01/dc01.ini -i inventory/dynamic/dynamic.sh playbook/playbook.yml from the command line, we get the expected result : ansible has computed the inventories and produced a merged one with the correct hierarchy and group_vars mapping

But when running the same on AWX, the dc01 group_vars are not parsed/available to the products hosts

We created an inventory on AWX with the ini files and dynamic.sh (all from SCM).

I’ve seen many issues on both github/awx and github/ansible but need help to leverage the issue the time the fixes will show up.
Most of them are closed but I don’t which one(s) our issue applies as we match most of the use cases !

Any help or indications welcome :slight_smile:

Best regards,

Instead of ansible-playbook to recreate how AWX generates the host vars; try using ansible-inventory to see what the outcome is.

Hi,

Just a follow up.

We end up using a custom script that simply calls :
ansible-inventory --list --export -i inventory/core/core.ini -i inventory/dc01/dc01.ini -i inventory/dynamic/dynamic.sh

We found some ungrouped things (into var/ungrouped, we saw the inventory script itself for exemple). We had to filter out those entries thanks to a pipe and jq : | jq "del(.ungrouped)"

After declaring this script into AWX, the mapping is fine.

Drawback : it is not so dynamic as we needed to duplicate/update the script for each dc.ini

But its a good workaround (as it works/parse/merge as expected !)

Regards,