I don't think there's a One True Way, it really boils down to the team
you're working
with and what makes sense for them given the mix of environments
they're managing.
Some people use one inventory for ALL their servers, if you need cross-site
plays that might be necessary. If you're lucky enough to not need that...
Personally I'm a huge fan of one inventory per site. I think I posted
it earlier,
but the gist is this layout:
.
├── california
│ ├── group_vars
│ │ ├── all
│ │ ├── group1
│ │ └── group2
│ └── hosts
├── newyork
│ ├── group_vars
│ │ ├── all
│ │ ├── group1
│ │ └── group2
│ └── hosts
└── site.yml
___ (other ad hoc playbooks etc. up at this level too)
Each playbook run just needs a '-i environment_name' and you're set.
It works great if you run isolated environments (prod / dev / staging)
which you want broad consistency between, but also are likely
to have differences in number of servers, types of users with SSH access,
levels of encryption, etc.
When it comes to setting vars, my general rule of thumb is to use
as few 'tiers' of variables as possible, otherwise it gets messy and its
hard to find where they're set. There are about a dozen places to set vars
in Ansible, you don't need to use them all. Generally, I go with:
1. environment-wide globals in $inventory/group_vars/all
(I used to set them inline in static inventories, but group_vars
support yaml syntax
and it plays nicer with dynamic inventories)
2. roles have 'sane' defaults in $rolename/defaults/main.yml.
Logfile paths, service account names, etc.
If no sane default exists, that's where it is documented
(via a commented out example var, with a suggestion where to set this).
This is essentially the 'README' for the role.
3. $inventory/group_vars/groupname - relevant to roles those
groups are performing. Easy to 'cat' to see how e.g. preprods
mongodb is setup.
4. host_vars/hostname is a Last Resort, usually on brownfield
sites to track inconsistencies.
"ls */host_vars/*" returns a handy list of servers we probably
need to rebuild.
In theory, this approach should mean diffing 2 inventory directories
gives a good idea of what's different between them.
I've built pretty complex stacks with
this approach from a single site.yml and it can work really well.