Interview Prep/Ansible/Roles, Collections and Galaxy

What are `tasks_from`, `vars_from` and `defaults_from` in `include_role`/`import_role`?

IntermediateConceptRoles, Collections and Galaxy
Answer

They let you run a role's alternate entry point instead of main.yml. A role can contain, for example, tasks/install.yml and tasks/configure.yml.

- ansible.builtin.include_role:
    name: postgres
    tasks_from: backup
    vars_from: prod

This turns a role into a small library of operations (install, backup, restore) invoked from different playbooks, without splitting it into several roles. handlers_from does the same for handlers.

All Ansible questions Roadmap: Ansible

More on Roles, Collections and Galaxy