Split up an ansible inventory

Hi,

I have my production inventory in one file (inventory/prod) and I'm
looking for a way to split up this file. For instance, I would like to
have a "servers" file and a "groups" file. The important thing is that
I need to define objects (hosts, groups) in the first file and use
them in the second.

I thought I had found a solution with the -i directory option, but
this doesn't seem to "concatenate" the files. It treats them as
independent inventories, so I get errors.

Is there a way to do that ?

Thanks.

​You can point -i to a directory which can have several files and
subdirectories.​

Le 14/01/23 11:10, Serge van Ginderachter claviotta :

​That's true. You'll need to look at the order in which the files are
parsed, and make sure you repeat certain references,

It's enough to e.g. define an empty group, in the one file which is defined
with hosts in another, etc.​

Le 14/01/23 12:57, Serge van Ginderachter claviotta :

> Yes, that's exactly what I said, but this doesn't work as expected,
> because in the second file I can't reference objects that are created
> in the first.
>

​That's true. You'll need to look at the order in which the files are
parsed, and make sure you repeat certain references,

It's enough to e.g. define an empty group, in the one file which is defined
with hosts in another, etc.​

I'm sorry but I don't think that information redundancy will simplify
my inventory… This is really not a solution.

Don't you think the expected behavior would be that all
non-executables files in the inventory directory be concatenated
before being read by lib/ansible/inventory/dir.py ?

All the static files in the directory should be parsed as a unique
inventory.

Le 14/01/23 14:23, Guillaume Subiron claviotta :

Le 14/01/23 12:57, Serge van Ginderachter claviotta :
>
> > Yes, that's exactly what I said, but this doesn't work as expected,
> > because in the second file I can't reference objects that are created
> > in the first.
> >
>
> ​That's true. You'll need to look at the order in which the files are
> parsed, and make sure you repeat certain references,
>
> It's enough to e.g. define an empty group, in the one file which is defined
> with hosts in another, etc.​

I'm sorry but I don't think that information redundancy will simplify
my inventory… This is really not a solution.

Don't you think the expected behavior would be that all
non-executables files in the inventory directory be concatenated
before being read by lib/ansible/inventory/dir.py ?

All the static files in the directory should be parsed as a unique
inventory.

I made a pull request : https://github.com/ansible/ansible/pull/5735