The Ansible documentation says "you can also use multiple inventory
files at the same time" but, AFAIK, that isn't entirely accurate.
If you give the '-i' flag a directory, then any inventory files under
that directory are indeed used, which is nice. However, what if you
want to use several inventory files that are *not* under a specific
parent directory? For example, maybe you want to use /etc/ansible/hosts
and ~/ansible/my_inventory. From what I can see, this isn't currently
possible. Is this correct?
I would think it would be nice if the '-i' option were changed to
accept multiple directories. I know you can currently give multiple
comma-separated hosts so maybe a different character would be used
to separate directories.
I don't think so. A symlink points to a single file (unlike logical
names in good old VAX/VMS). So, it wouldn't be possible to use both
a system inventory and a personal one.
Maybe if you made your user inventory a dir and then had a symlink in there to the shared inventory?
I have remembered now that you can use an executable python script as a source of inventory, so you could read both user and shared inventory in that, which might be a cleaner alternative.
Maybe if you made your user inventory a dir and then had a symlink in
there to the shared inventory?
I see what you mean. That might be a good workaround but it sure
seems to me that expanding the '-i' option would be a better
solution.
I have remembered now that you can use an executable python script as
a source of inventory, so you could read both user and shared
inventory in that, which might be a cleaner alternative.
Again, that sounds like a fine workaround but there should be
a clean and simple way of doing this.
Simply accepting multiple `-i` options would be enough, no need for
special characters.
In addition, inventory locations could be URLs in addition to file
locations. That would decouple the inventory so it can be easily
distributed to new machines etc.
Obviously the inventory script could download a URL, but that still
requires a local executable to be created and maintained.
Maybe I'll give it a try. The only thing I can think of that
might be a problem is distinguishing arguments that are hostnames
from those that are inventory files. In a way it's too bad that
hostnames are allowed in a '-i' argument.
"specify inventory host path (default=/etc/ansible/hosts) or comma
separated host list."
How would it be possible to distinguish a comma separated host list
from a comma separated inventory host path list?
For example, would
-i a,b,c
be the hosts "a", "b", and "c", or the files (or directories) "a", "b",
and "c"?
A very quick glance at inventory/__main__.py(parse_inventory) makes me
think that the elements of the string are first checked to see if
they're a host, and then checked to see if they're a directory or file.
The presence of a comma in itself isn't enough to differentiate paths
an host. Of course, I just started reading Ansible source so I'm not 100% sure I have this right.
I was thinking that maybe requiring that host paths contain slash
characters, as part of either an absolute or relative path, would work.
Or maybe saying if the string argument to "-i" ends in a comma, then
the whole string would be considered a host list, but if it ends in
anything other than a comma, it would be a inventory host path list.