Reusing inventory config

97 views
Skip to first unread message

Michael Mahemoff

unread,
Jun 3, 2014, 9:20:30 PM6/3/14
to ansible...@googlegroups.com
As I have separate "staging" and "production" inventory files, I end up duplicating some group compositions (e.g. databases:children is mysql:children and redis:children, that kind of thing). I'm wondering if there's a way to consolidate that logic, such as a directive to include a file. Or maybe some trick I'm missing here.

James Cammarata

unread,
Jun 4, 2014, 10:08:32 AM6/4/14
to ansible...@googlegroups.com
If you're dealing with any significant number of hosts (ie. more than a hundred), we generally recommend using a dynamic inventory script of some kind. Beyond that, the INI syntax doesn't really allow for any includes unfortunately.


On Tue, Jun 3, 2014 at 8:20 PM, Michael Mahemoff <mic...@mahemoff.com> wrote:
As I have separate "staging" and "production" inventory files, I end up duplicating some group compositions (e.g. databases:children is mysql:children and redis:children, that kind of thing). I'm wondering if there's a way to consolidate that logic, such as a directive to include a file. Or maybe some trick I'm missing here.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bbe12ef1-69ea-4e65-9a6e-0359246cc017%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dick Davies

unread,
Jun 5, 2014, 3:05:46 AM6/5/14
to ansible list
I do the per environment inventories too (partly because they're
datacenter/vagrant)
and had a few groups just to target one-off plays.

My per-environment settings usually tuck into

[all:vars]

in the inventory - I've no idea how I'm going to map that to a dynamic inventory
yet, probably a lot of set_fact roles to set everything up.

I keep them in step by diffing :(

Re: the group composition - I needed that for some one-off plays, it
turns out you can target multiple groups in a play with something like

.....
- hosts: mysql:redis
sudo: yes
tasks:
.....

Michael DeHaan

unread,
Jun 6, 2014, 8:34:20 AM6/6/14
to ansible...@googlegroups.com
Don't do "all:vars", use a "group_vars/all" file instead.

Not only is it cleaner for a static inventory, but it's usable with dynamic ones as well.




Dick Davies

unread,
Jun 6, 2014, 9:08:13 AM6/6/14
to ansible list
Yeah we're about to try some of the cloud providers, I know this is
going to bite us.

problem with group_vars/all is that it's 'in the tree' - I'm trying to
find a way to
have preprod_hosts and production_hosts contain everything environment-specific,
so we can ensure roles/ group_vars/ etc. don't vary across different
environments.
> https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgx7v9AByVNy%2BDjszL3k1Ob%2BBK73J2uHWK%3DmOhduSekbaw%40mail.gmail.com.

Michael DeHaan

unread,
Jun 8, 2014, 11:30:03 AM6/8/14
to ansible...@googlegroups.com
"problem with group_vars/all is that it's 'in the tree' - I'm trying to
find a way to"

You can keep this alongside your inventory (which most people do) rather than alongside your playbook, if you like.





Dick Davies

unread,
Jun 9, 2014, 11:42:27 AM6/9/14
to ansible list
Ah, mine are all lumped in together, like this:

ansible-mystack:$ tree -L 1
.
├── Vagrantfile
├── ansible.cfg
├── group_vars
├── preprod_hosts
├── prod_hosts
├── roles
├── site.yml
└── vagrant_hosts

Are you talking about having a group_vars per inventory then?
Trying to figure out how that would look.
> https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgw1thNLkz70wxRpOE9ov8p-%3Dk4DQdmBxwjAqFtA%3DQ903g%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages