Solution for Making HTTPD Restart Idempotent

Kriti Dubey
2 min readMar 20, 2021

🔰 Task 11.3:- Restarting HTTPD Service is not idempotence in nature and also consumes more resources. Suggest a way to rectify this challenge in the Ansible playbook.

first, let us learn about what is idempotence:

What is idempotence?

A service/operation is known as idempotent if the result of performing it once is the same as the result of performing it repeatedly without any intervening actions.

Restarting httpd is not idempotent so whenever we run the ansible-playbook the httpd services will also restart and this will lead to more consumption of resources.

Here, we want the httpd service to restart only when there is any change in the configuration files to reduce the resource consumption. So, to achieve this we can use handlers as they execute the services only when there is some change in the files.

let us learn more about handlers...

Handlers

Handlers are like tasks in the ansible-playbook. But, Handlers execute the services only when it detects some change in the machine. Like in the given ansible-playbook the handlers will check for the changes and if it detects it then only it will restart the httpd service.

Ansible-Playbook

Running the above playbook

The handler hasn't run as no change has been detected.

--

--