From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Adding roles to a playbook

Adding roles to a playbook

- [Instructor] There are several ways to call a role from a playbook, and your choice really comes down to preference, though, I'll make a case for my favorite method. I'm starting from this template playbook named nginx-role.yml. First, I'll show you my least favorite method, which is to call a role from a role section. So here, I'll add roles, similar to the way you'd add the task section. Then, under that, I'll list the roles in order I'd like them to run. Dash, nginx. That's it. I'll run the playbook. ansible-playbook -i inventory nginx-role. I see here in my output that it did, indeed, grab the role and run it. Let me modify my playbook to show you my favorite method to use. I'll start by commenting out the entire roles section. I'll now create a standard task section. tasks. I'll now add a single task. name: Run nginx role. The module is: include_role. The final parameter is to specify the role name with name: nginx. I'll fire this one off as well. Same result, as expected. So…

Contents