Making the HTTPD Service Idempotence in Nature using Ansible Playbook

Writing a playbook to make HTTPD service Idempotence dor utilizing Computer Resource properly.

Greetings Everyone!!! I hope you all are fine and doing well.

In this blog, we will be creating an Ansible Playbook that will help us install HTTPD in a system and run the service idempotence when the playbook is running again. If you need some insight related to Ansible, you can check this blog.

So let’s get started with the task…


Below is the code from my GitHub, which I wrote for a regular installation of httpd.

So What is the issue?

As in the above image, you can see that we have installed and started the httpd service, and it is running in our managed node.

When we ran the same playbook, we can see that the task “Started HTTPD Service” is changed, which means it ran again, which will mean it restarted the HTTPD service.


Handlers: Handlers in Ansible is a concept in which we will write the task inside it when we want to run the task when some other tasks notify it to run. We will use it on the task where the configuration file will be changed, and if that task runs, it will notify the handler task of restarting HTTPS. If it didn’t run HTTPD task also won’t run.

Notify: Notify is a concept we add to the task which needs to be run to run the handlers task. Here changing the configuration file task will notify handlers to run.

Here is the copy of the code which I am using to make the HTTPD service. Idempotence nature, and here are the modifications I made in our old playbook.

As you can see in this code, at last, there is a feature called handlers, and inside the task of “Copying Configuration File,” I have used notify for the handler called “RestartService.”

If we have many handlers then we denote then with their name on the notify.

So this way, when I copy a configuration file in the httpd configuration, it will notify the handler and run the handler task.

In the above image, you can see the task of “Copying Configuration File” is changed, and at last, the handler task is also running.

But when I reran the playbook like I did last time, this time it didn’t change my Copying task, so my Handler task of restarting HTTPD also didn’t run. Now, whenever I change my configuration file, only HTTPD restarts, and that is what we wanted.


You can check my GitHub link down for the code of the same task.

I hope I have cleared all the doubts and presented my point clear. If you have any doubt and confusion, always feel free to contact me on my LinkedIn

Thank You for your time. Have a Good Day.

I blog about ML, Big Data, Cloud Computing. And improving to be the best.

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