How do you design inventory groups?
AdvancedProductionProject Structure and Design
Answer
Think of groups on three independent axes and combine them with intersections, instead of one deep tree:
- function:
web,db,cache - environment:
env_prod,env_stage - location:
region_ap_south_1,az_a
A play targets hosts: web:&env_prod. In a cloud, derive groups from tags with keyed_groups, so groups can never go stale. Variables go in the group they describe (function settings on web, endpoints on env_prod). Avoid defining the same variable on two sibling groups, because the alphabetical merge order will bite you.
More on Project Structure and Design
What does a production Ansible repository look like?BeginnerMonorepo or separate repos for roles? How do you decide?IntermediateHow do you structure inventories for dev, stage and prod?BeginnerHow do you prevent someone from running a playbook against production by accident?IntermediateWhat does "thin playbooks, fat roles" mean?IntermediateWhat makes a well-designed role?Intermediate