Creating the Roles Structure with Ansible-Galaxy
Sprawling infrastructure and snowflake woes? Then Ansible is the solution you need!
Ansible is designed to be minimal in nature, consistent, secure and highly reliable! Ansible is a highly sought after skill in the marketplace with an extremely low learning curve for administrators, developers and IT managers.
The "Ansible Essentials: Simplicity in Automation Technical Overview" course introduces you to Ansible automation and configuration management, provisioning, deploying, and managing compute infrastructure across cloud, virtual, and physical environments.
By taking this course you'll learn just how easy it is to use Ansible to build consistent and repeatable infrastructure environments using Ansible playbooks.
In this video, I am now going to talk to you about how to create the role structure using the ansible-galaxy command. So I’m in my terminal window and I have my project ready to go, but I want to create the role structure, so what I am going to do is, I am first going to create a roles directory to contain my roles. So make your roles, then I am going to cd into it, and then I am now going to use the ansible-galaxy command to create the structure, so if I do an ansible-galaxy init and then dash dash (--) help, you can see the options that I have, so init, then the role name, is how I would create the structure. And you can see the additional options that you can have, so there is a force option to overwrite an existing role, I have the ability to print out the version, make it more verbose, I don’t ever usually use those options just because all I am really doing is, just creating the structure.
So I’ll clear this out, and then I will do ansible-galaxy init and I am going to make two roles, common, and you can see that common was created successfully, and then I am going to create another one called apache, and you can see that apache was created successfully. So, now that I have actually created the role structure for my apache and common roles, to show you what those look like, so I’ll do an ls on the apache directory, and you can see this is similar to what I demonstrated in the slides for the role structure.
I have got my handlers directory, my task directory, I have got a templates directory, and this is where I am going to place individual components of the basic playbook that I already created. So the same thing with the common role, it’s the same structure, got the same directories, and actually if I do an ls on common and then tasks, there is already a file in there called main.yml which I am going to place my individual task pieces in there. And the way that the role structure works is, is that I don’t have to put a tasks or a handlers header inside of these files because Ansible's able to discover that they’re task files or handlers files, just because they are already in this predefined directory structure.
So, now that I have demonstrated how to create the role structure, join us in our next video where we’re going to discuss how to break the existing playbook into the role structure.
Jeremy is a Content Lead Architect and DevOps SME here at Cloud Academy where he specializes in developing DevOps technical training documentation.
He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 25+ years. In recent times, Jeremy has been focused on DevOps, Cloud (AWS, GCP, Azure), Security, Kubernetes, and Machine Learning.
Jeremy holds professional certifications for AWS, GCP, and Kubernetes.