From the course: Complete Guide to Configuration Management Using Ansible

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Using handlers for conditional task execution

Using handlers for conditional task execution - Ansible Tutorial

From the course: Complete Guide to Configuration Management Using Ansible

Using handlers for conditional task execution

The next conditional that we will discuss is the handler. So what was the handler again? Well, handlers run only if the triggering task has changed something. And by doing so, you can avoid unnecessary task execution. And that is particularly useful if the task execution is interrupting services. If you want to run a handler, you'll use a notify statement in the main task, and a notify statement is calling the name of the handler. Now the most common use of handlers is to restart processes or reboot hosts only when it is necessary. Here we have a code example. Let me run this code example for you. So let me call it handler1. And in handler1, I am using name: showing handlers; and hosts, let's do a real host this time, because now for handlers, you want to do something. Debug isn't really doing anything. So tasks and the tasks, well, I am going to use name: copy a file, and then the copy module. And the copy module is using src: /tmp/index.html and destination:…

Contents