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

Geetansh Sharma
3 min readJan 23, 2021

--

What is Idempotence?

An idempotent operation is one that can be applied multiple times without changing the result beyond the initial application, such as multiplication by zero.

We have seen that when we restart the HTTPD service using Ansible playbook, it is always in changed state and hence consumes more resources.

To overcome this problem we make use of Ansible handlers.

What are Ansible Handlers?

Handlers are just like regular tasks in an Ansible playbook but are only run if the Task contains a notify directive and also indicates that it changed something.

We can use handlers to solve our problem here as follows:-

My playbook with handlers:-

Now, let’s run the playbook :-

Here, copying the file module is my httpd start module. We can see that handler has run successfully.

Now, let’s check whether restarting HTTPD has been handled by handler or not by re-running our playbook:-

The green color clearly depicts that the handler has handled this task and prevented HTTPD from restarting as it is already running. Hence, the problem is successfully solved by the use of handlers.

My Web Page has also been deployed:-

***********THANKS FOR READING**********

--

--

No responses yet