Roles and Galaxy
Part of the Ansible course
Sooner or later you end up with two playbooks that both install nginx, both drop the same config template, and both restart the service afterward, because two different projects both happened to need a web server. Copy the tasks from one playbook into the other and you now have two copies of the same logic to keep in sync, and the first time you fix a bug in one copy and forget the other, they quietly drift apart.
A role is a reusable bundle of tasks, templates, and default values that you can drop into any playbook by name, instead of writing the underlying logic out again for every project that happens to need the same thing. Think of it the way a construction crew thinks of a prefabricated wall panel: the panel was designed once, built once, tested once, and now it gets bolted onto whichever building needs a wall in that...
Want to learn Ansible Roles and Galaxy in a real environment?
Click below, get a fresh Linux box with Ansible ready to go, and work through Roles and Galaxy hands-on with an AI tutor that knows your code.
Start this lessonRoles and GalaxyWhat you'll learn
- Role structure
- Tasks/main.yml
- Defaults
- Templates folder
- Include_role
- Ansible-galaxy install
Read this lesson in your language
All lessons in this course
12 lessons- 1What Is Ansible20 min
- 2Inventory and Ad Hoc Commands25 min
- 3Your First Playbook30 min
- 4Tasks, Modules, and Handlers30 min
- 5Variables and Facts30 min
- 6Templates with Jinja230 min
- 7Loops and Conditionals30 min
- 8Roles and Galaxy35 min
- 9Vault and Secrets25 min
- 10Tags and Debugging25 min
- 11Collections and Plugins25 min
- 12Capstone: Multi Host Deploy60 min
