From the course: Ansible: From Basics to Guru by Pearson

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: Ansible: From Basics to Guru by Pearson

Using handlers for conditional task execution

The next conditional that we will discuss is the handler. So what was a 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 will use a notify statement. in the main task, and the 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 that is necessary. Here we have a code example. Let me run this code example for you. So let me call it handler1. And in handler one, 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, copy a file, and then the copy module and the copy module is using srctmpindex.html and destination var…

Contents