Ansible Handlers
Learn how to manage event-based actions using Ansible handlers.
We'll cover the following...
What are handlers?
Handlers are event-driven tasks that are only executed in response to specific events or conditions. These events are typically associated with changes made by tasks, such as configuration file updates or package installations. Handlers are usually triggered during or after the execution of tasks within a playbook. A task notifies a handler by name using the notify
attribute, and when this is done, Ansible queues the handler to be executed after all tasks run. Handlers ensure that actions are taken only in response to relevant events, adding a level of control and automation that are only based on specific triggers.
Here is a typical syntax of a handler:
---# Initial configuration for our playhandlers:- name: name_of_handler # Define the handler's namemodule_name:parameter1: value1parameter2: value2
In the code snippet above, we define a handler named name_of_handler
with the corresponding module name to use and the parameters. We can then call this handler from a task by using the notify
...