🔰 Restarting HTTPD Service is not idempotence in nature 🔰

What is Idempotent Ansible?
The principle that enables Ansible to be declarative and yet reliable is idempotence, a concept borrowed from mathematics. An idempotent operation is one that can be applied multiple times without changing the result beyond the initial application, such as multiplication by zero. Ansible modules are idempotent.
It means if the current requirement is already present then it won’t change anything.
TASK
Restarting HTTPD Service is not idempotence in nature and also consume more resources suggest a way to rectify this challenge in Ansible playbook.
APPROACH
To solve this issue we take the help of Handlers.
Understanding Handlers
Handlers are just like normal tasks in an Ansible playbook but they run only when if the Task contains a “notify” directive. It indicates that it changed something. And when any change is detected then it notifies the respective handler and the task completes.
Sometimes you want a task to run only when a change is made on a machine. For example, you may want to restart a service if a task updates the configuration of that service, but not if the configuration is unchanged. Ansible uses handlers to address this use case. Handlers are tasks that only run when notified. Each handler should have a globally unique name.
Pre-requisite for this task :
Two RHEL OS on your system with yum configuration.
🔹Controller Node
🔹Managed Node
✔️So let’s create playbook in controller node which can configure apache httpd webserver on target nodes with the help of handlers.

✔️Let’s run our playbook

So now our handler will only run when any change is made on config file which we have used in template module and notify keyword used with template module will notify to handler if any if change is made or not.
✔️Let’s try running our playbook without changing anything to config file:

This time handler won’t run.
TASK COMPLETED Successfully✌🏻👨🏻💻
Thanks for reading !!!😊✨