Handlers action to take when a change occurs
module has idempotent, so when the remote system is changed, you can replay playbooks to achieve recovery
Objective. The playbooks itself can identify this change, and there is a basic event system that can
Respond to this change
Notify actions are triggered at the end of each task in playbook, and even if there are many different
Task notification changes occur, notify actions will only be triggered once
For example, multiple resources indicate that because a configuration file has been changed, Apache needs to re-
The new boot, but the restarted operation will only be executed once
Here is an example of restarting two services when the contents of a file are changed
-Name:template configuration file
Template:src=template.j2 dest=/etc/foo.conf
Notify
-Restart memcached
-Restart Apache
Notify the following is the handlers
Handlers is also a list of some tasks, referenced by their names, and they have nothing to do with the general task
Difference. Handlers is performed notify by the notifier, if not notify,handlers will not be executed
No matter how many notifier notify, wait until all the tasks in play are completed
Handlers will not be executed once.
Here is an example of a handlers
Handlers:
-Name:restart memcached
Service:name=memcached state=restarted
-Name:restart Apache
Service:name=apache state=restarted
The best application scenario for handlers is to restart the service or trigger the system restart operation,
Less use.
This article from "Eight Miles" blog, declined reprint!
Ansible Study notes 5-playbooks handlers