Tasks, Modules, and Handlers
Part of the Ansible course
Picture a playbook that manages a web server. It has three tasks that each touch a different config file, and after any of them changes, the service needs a restart to pick up the new config. The obvious approach, restarting the service as its own task every time, is wasteful: if none of the three config tasks actually changed anything, you just restarted a perfectly fine service for no reason.
Ansible has a purpose-built answer for exactly this shape of problem: handlers. A handler is a task that only runs when something else tells it to, and even then, only once, no matter how many things told it to.
Want to learn Ansible Tasks, Modules, and Handlers in a real environment?
Click below, get a fresh Linux box with Ansible ready to go, and work through Tasks, Modules, and Handlers hands-on with an AI tutor that knows your code.
Start this lessonTasks, Modules, and HandlersWhat you'll learn
- Tasks
- Modules
- Handlers
- Notify
- Changed_when
- Service restart pattern
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
