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 - 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
-
-
-
-
-
-
-
-
-
(Locked)
Learning objectives43s
-
(Locked)
Conditionals overview1m 37s
-
(Locked)
Using loop to process a list of items11m 24s
-
(Locked)
Using handlers for conditional task execution7m 42s
-
(Locked)
Using when to run tasks in specific situations11m 16s
-
(Locked)
Using register to work with task results4m 9s
-
(Locked)
Using blocks5m 31s
-
(Locked)
Managing failure with the fail module5m 33s
-
(Locked)
Using assert5m 29s
-
(Locked)
Lesson 7 lab: Using when to create idempotency46s
-
(Locked)
Lesson 7 lab solution: Using when to create idempotency5m 47s
-
(Locked)
-
-
-
-
-
-