What is a good Ansible project structure?
⚡
Quick Answer
A conventional layout: inventories/ (per-environment hosts), roles/ (reusable units), playbooks/, group_vars/ and host_vars/ (variables by scope), and ansible.cfg for configuration.
Detailed Answer
Separating inventories by environment (dev/stage/prod) prevents cross-environment mistakes; roles keep tasks/templates/handlers reusable and DRY; group_vars/host_vars scope variables cleanly. This structure scales from a few playbooks to a large automation codebase and plays nicely with Ansible Galaxy for sharing roles.
Code Example
inventories/{dev,prod}/hosts
roles/
playbooks/
group_vars/
host_vars/
ansible.cfg💡
Interview Tip
Highlight per-environment inventories and roles for reuse — organization is what keeps Ansible maintainable at scale.
ansiblestructureroles