“🔰 Restarting HTTPD Service is not
idempotence in nature and also consume more
resources suggest a way to rectify this challenge
in Ansible playbook"
To know this first we need to understand what is Ansible and how idempotence is related to ansible.

In short what ansible is…
Ansible is an open-source software that automates software provisioning, configuration management, and application deployment.Ansible is included as part of the Fedora distribution of Linux, owned by Red Hat, and is also available for Red Hat Enterprise Linux, CentOS, openSUSE, SUSE Linux Enterprise, Debian, Ubuntu, Scientific Linux, and Oracle Linux via Extra Packages for Enterprise Linux (EPEL), as well as for other operating systems. Ansible is procedural rather than declarative. In ansible, we define what we want to do and ansible go through each and every step for that.Ansible uses SSH to connect to remote hosts and do the setup, no software needed to be installed beforehand on a remote host. It’s simple, powerful and flexible.
To get the detailes information about ansible you can read my previous below blog 👇
“All about Ansible…” by Jyotisp https://medium.com/@jyotisp710/all-about-ansible-2cc02ae8e985
How ansible is idempotence while configuring webserver:
- Idempotence refers to the concept that if particular task is already performed inside the managed/target node of ansible then ansible avoids that task.
- Except some modules in ansible all modules support idempotence
- But while we run the service task of webserver and include the state as restart i.e when we restart web server then this task doesn’t support idempotence.
- As it doesn’t support idempotence the service task for restarting a server runs every time we execute a playbook. This consumes more system resources.
- So here we will find a way in this blog to overcome this challenge.
So let’s start….
- I have created a separate variable file which includes the paths,mount points, etc.
2. This is the var.yml file

3. We need a configuration file of server to update the configuration in the target OS.
Here we are changing the document root of the web server , so we need to update the path of new document root along with the ip and port of the target OS. So this lw.conf file is in our system and we will copy this in the target OS.

4. Now our main playbook comes- webserver.yml
5. This includes all the tasks to be performed.
Here inventory file consists the IP of the target node where we need to configure web server.

- Here first we are creating a directory to mount the dvd for updating the yum repository and installing the httpd server.
- Then I have mounted the dvd which has a iso file on the newly created directory
- Then configure the yum repository for web server
- Then install the httpd service
- Now as mentioned above we are creating new document root, so in next step here we are doing the same
- Update the web configuration file and notify the handler- restart service when there is a change in the configuration file.
- Now copy the web file inside new document root
- Handle the firewall.
- Handler for restarting the server.
- This handler will only execute when there is change in the configuration file of server.
6. Now run the playbook
When there is change in the configuration file then the httpd service needs to be restarted.
So here when we run the playbook and perform any change in the configuration file then the handler gets executed.
This can be seen in the below image

In the end we have a handler running.
But if we run the playbook without any changes in the configuration file then there’s no need to restart the service and so the handler doesn’t executes.

We can see the server running successfully through the browser.

So, here we have achieved the idempotence for the restart state of webserver.
So we completed the challenge 😌😌😎😎
I hope all will like this blog and do comment for my blogs.✍️✍️