How do you keep variables from turning into an unmanageable mess?
AdvancedProductionProject Structure and Design
Answer
- Few places: role
defaultsfor tunables,group_varsper environment,host_varsas rare exceptions. - Avoid
vars/main.ymlfor things users might change, and avoidset_factfor values that should stay overridable. - Never rely on extra vars in normal operation.
- Prefix names and validate with
argument_specs. - Use
ansible-inventory --host <name>and-vvvto see the final merged values.
Treat precedence bugs as a design smell: if you need a table to explain where a value comes from, simplify the layout.
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