How do you structure inventories for dev, stage and prod?
BeginnerProductionProject Structure and Design
Answer
One inventory directory per environment, each with its own group_vars/ and host_vars/, sharing the same playbooks and roles. Environment-neutral values go in group_vars/all, environment values in the environment's directory.
ansible-playbook playbooks/site.yml -i inventories/stage/
ansible-playbook playbooks/site.yml -i inventories/prod/ --limit web
This makes it obvious which environment a command targets and keeps prod secrets (separate vault) out of dev's reach.
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 prevent someone from running a playbook against production by accident?IntermediateWhat does "thin playbooks, fat roles" mean?IntermediateWhat makes a well-designed role?IntermediateWhat goes into a project-level `ansible.cfg` for production?Beginner