I have inventory = ../inventories in my ansible.cfg. This finds all possible inventory files (static as well as dynamic ones) inside the directory `../inventories’.
Now I want to extend this a bit and add a subdirectory of ../inventories where a main.yml serves as first point of contact, so to say
But I’m a little confused. If you specify inventory = ../inventories, it will pull in all the files, including from the patroni subdirectory. (I think you know that already.)
What’s confusing me is, what do you expect to be the final result, and in what way would it be different if it parsed inventories/patroni/main.yml before any others?
Edit: I’ll go a step farther and say — having thought of no use case for this — that if you’re building in differences that depend on the order these inventories are parsed, you should reconsider.
Furthermore, in my tests, although the above configuration did cause the ../inventories/patroni/main.yml to be parsed first, that same inventory file was parsed a second time when the ../inventories tree was traversed. Run ansible-inventory with lots of "v"s and grep for ^Parse to see the parsing order.
actually I wasn’t sure it extends to subdirectories also.
Maybe I just have a connection problem with one of the dynamic inventories and due to that it never arrives at the subdirectory inventory and just hangs. Will have to verify that later and report back.
EDIT:
it is exactly as you suggested. The structure in the subdirectory workes without a specific mentioning.
It was just the missing connectivity on my dev machine with the source of a dynamic inventory on the higher level, that made it seem not to work on first sight.
We had a similar problem where an inventory script took minutes to run — far too long to run on each ansible-* invocation. Our solution was to periodically cache a copy of that inventory and use the cache. That worked because that inventory wasn’t very dynamic. We later dropped it entirely with a coincident data center migration. (Yay!)