Ansible roles are basically like functions in java, c++. They are a small, independent block of codes that perform a specific task and are called in the playbook. Ansible roles make complicated playbooks easier to read and understand. These roles can be reusable. You can just pick these roles for another project and make the required changes.