What makes a well-designed role?
IntermediateProductionProject Structure and Design
Answer
- Single responsibility (nginx, not "web stack plus monitoring plus users").
- A documented interface: prefixed variables in
defaults/, validated byargument_specs. - Idempotent, supports check mode, and tested with Molecule on the OSes you run.
- No hidden coupling to inventory group names or other roles' variables.
- Handlers with unique, prefixed names.
- Sensible defaults that work out of the box, with secure settings on by default.
If using the role requires reading its tasks, the interface is not good enough.
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 goes into a project-level `ansible.cfg` for production?Beginner