Split up an ansible inventory

833 views
Skip to first unread message

Guillaume Subiron

unread,
Jan 23, 2014, 4:39:22 AM1/23/14
to ansible...@googlegroups.com
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.

--
Guillaume Subiron
Mail - mae...@subiron.org
GPG - 5BC2 EADB
Jabber - mae...@im.subiron.org
IRC - maethor@(freenode|geeknode)

Serge van Ginderachter

unread,
Jan 23, 2014, 5:10:37 AM1/23/14
to ansible...@googlegroups.com

On 23 January 2014 10:39, Guillaume Subiron <mae...@subiron.org> wrote:
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.

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

Guillaume Subiron

unread,
Jan 23, 2014, 6:04:47 AM1/23/14
to ansible...@googlegroups.com
Le 14/01/23 11:10, 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.

Serge van Ginderachter

unread,
Jan 23, 2014, 6:57:37 AM1/23/14
to ansible...@googlegroups.com

On 23 January 2014 12:04, Guillaume Subiron <mae...@subiron.org> wrote:
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.​

Guillaume Subiron

unread,
Jan 23, 2014, 8:23:16 AM1/23/14
to ansible...@googlegroups.com
Le 14/01/23 12:57, Serge van Ginderachter claviotta :
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.

Guillaume Subiron

unread,
Jan 23, 2014, 10:49:26 AM1/23/14
to ansible...@googlegroups.com
Le 14/01/23 14:23, Guillaume Subiron claviotta :
> Le 14/01/23 12:57, Serge van Ginderachter claviotta :
> > On 23 January 2014 12:04, Guillaume Subiron <mae...@subiron.org> wrote:
> >
> > > 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
Reply all
Reply to author
Forward
0 new messages