Trigger tasks with handlers

Okay; you have installed and removed a series of packages in your system. You have copied files to/from your server. And you have changed many things in the server by using an Ansible playbook. Now, you need to restart a few other services, or add some lines to the files, to complete the configuration of the service. So, you should add a new task, right? Yes, that's correct. However, Ansible provides another great option, called handlers, which will not automatically execute when it hits (unlike tasks), but will rather be executed only when it is called. This provides you with the flexibility to call them upon the execution of tasks inside the play.

Handlers have the same alignment as the hosts and tasks, and are ...

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.