🔰 Restarting HTTPD Service is not idempotence in nature 🔰

🔰 Task : 11.3 Restarting HTTPD Service is not
idempotence in nature and also consume more
resources suggest a way to rectify this challenge
in Ansible playbook”

What is Ansible?

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning. Automation is crucial these days, with IT environments that are too complex and often need to scale too quickly for system administrators and developers to keep up if they had to do everything manually. Automation simplifies complex tasks, not just making developers’ jobs more manageable but allowing them to focus attention on other tasks that add value to an organization. In other words, it frees up time and increases efficiency. And Ansible, as noted above, is rapidly rising to the top in the world of automation tools. Let’s look at some of the reasons for Ansible’s popularity.


An operation is idempotent if the result of performing it once is exactly the same as the result of performing it repeatedly without any intervening actions.


To solve this idemotency 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.

::::::::::::::::::::::::::LET’S GET STARTED::::::::::::::::::::::::::

Let’s first create playbook in controller node which can configure apache httpd webserver on target nodes with the help of handlers.👇


Here we see our handler will only run when any change is made on config file which have we used in template module and notify keyword used with template module, it will notify to handler if any if change is made or not.

Now try to run the playbook without doing any changes in the configuration file 👇

Here we see no changes occur in the playbook because we did’nt perform any changes in the config file.

Now here i do a change in the configuration file 👇

Now try to run the playbook.

Yeah, what we see as soon as i do any changes in the configuration file only when handler start the service

:::::::::::::::::::🙌TASK COMPLETED🙌:::::::::::::::::::::::

If any query related to this task please comment.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Swarnim Kashyap

Swarnim Kashyap


RedHat Certified Engineer| DevOps Enthusiast | Big Data Hadoop | RedHat Linux 8| AWS Cloud | GCP | Azure Cloud |GIT & GitHub |Python