doing something like ansible <hostname/pattern> -m debug -a "var=hostvars[inventory_hostname]" and looking at the group_names object might help clue you in on what’s going on?
What appears to be happening is that its processing path2/inventory/group_vars/pgdb.yml last, which is not what I’d expect to be happening.
In 3d example, as we see, wins second inventory with two same vars. It means, that 1st inventory didn’t use for resolving conflicts - it’s expected.
variables are flattened to the host level and last one wins when there is a conflict
I have a host in two groups: “pgdb” and “server”. Last var, in alphabetically order, always wins(from “server”).
And when I set only one inventory(2nd example), it works.
But it didn’t work with two inventories(3d example).
It is the question.
doing something like ansible <hostname/pattern> -m debug -a "var=hostvars[inventory_hostname]" and looking at the group_names object might help clue you in on what’s going on?
It is always one host for testing. I just modify ansible.cfg. Groups are identical.
What appears to be happening is that its processing path2/inventory/group_vars/pgdb.yml last, which is not what I’d expect to be happening.
When I set only one(inventory path2), processing is going in right order.
When I set two inventories, it looks like processing works only with first found var.
That documentation applies to inventory sources. group_vars aren’t inventory sources themselves - for those, the order depends on the order of the host’s groups. The documentation should be clearer about this. For example, with this inventory file:
[server:children]
pgdb
[pgdb]
host
The ancestor groups are always ordered first, so the variable plugin receives the groups in the order server, pgdb, causing the pgdb variables to win. If I don’t use child groups, then it seems to be alphabetical.
i’m not sure what you mean by ‘break’, as i stated above there is a precedence, by inventory source and playbook dir as the locations which then get processed by vars plugins (host_group_vars in this case). Then variables get merged by entity, first by groups, with internal precedence as stated above and with the ‘all’ group being treated specially. Then via the host name.
I believe the issue is that you are assuming that inventory sources are not part of the precedence. While this is documented in several places, the main ‘list’ is mostly oriented to a single inventory and assumes the default vars plugin, I have been planning on updating to be more explicit about other cases.