Sobes.tech
Junior — Middle

How do playbook, roles, and collections differ in functionality and purpose in Ansible?

sobes.tech AI

Answer from AI

In Ansible, there are different levels of automation organization:

  • Playbook — a file (usually in YAML format) that describes a sequence of tasks to be executed on managed hosts. The playbook defines what to do and in what order, such as installing packages, copying files, starting services.

  • Roles — a way to structure and reuse configuration. A role contains a set of related tasks, files, templates, and variables organized in a specific directory structure. Roles allow dividing configuration into logical parts and easily including them in a playbook.

  • Collections — larger packages that can contain roles, modules, plugins, and other Ansible components. Collections simplify distribution and reuse of code, and enable sharing through Ansible Galaxy or other repositories.

Summary:

  • Playbook — a script for executing tasks.
  • Role — a structured set of tasks and resources for specific functionality.
  • Collection — a package combining roles, modules, and other components for easy distribution and use.