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,700 courses taught by industry experts.
Role creation - Ansible Tutorial
From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts
Role creation
- [Instructor] There are a couple of schools of thoughts on creating roles. In essence, you are deconstructing a playbook and putting it into a role structure. So when I'm teaching folks how to create a role, my go-to is to always suggest creating a playbook that contains all the pieces of the role that you want and make it function correctly. Then cut and paste those various pieces from the working playbook into a role. Nice and simple. Some folks like to develop a role, then create a playbook to utilize it, and in my opinion, it's a more difficult task for complex operations as I have to move between multiple places to figure out what's going on. This I believe, is a more advanced way to develop roles. It's not wrong. It just can be more complex. With this in mind, I'll start with one of my existing playbooks and construct a role from it. I'll build from my handlers.yml playbook where I'm installing and configuring nginx. I'll name my role nginx, and I'll build the folder and file…