DevOps / Ansible Interview questions
What is the difference between roles and collections?
| Role | Collection |
| A single reusable unit: tasks, handlers, templates for one purpose. | A packaging format that can bundle multiple roles, modules, plugins, and docs together. |
| Distributed individually via Ansible Galaxy. | Distributed as a versioned package (also via Galaxy or private repositories). |
| Referenced directly by name in a playbook's roles: list. | Referenced with a namespace, e.g. community.docker.docker_container. |
A role is the older, simpler unit of reuse focused purely on tasks/handlers/templates for one job. A collection is the modern distribution format that can contain many roles plus custom modules, plugins, and inventory sources, all versioned and namespaced together (like community.docker or amazon.aws). In practice they're complementary rather than competing: a collection often contains one or more roles inside it, and most of Ansible's own built-in functionality now ships as the ansible.builtin collection.
More Related questions...