Restarting httpd Service in idempotence nature

Sourav Dinda
3 min readJun 3, 2021

--

Hello Guys, Back with another article. In this you will find how we can automate Apache WebServer using the linux automation tool i.e Ansible.

In this article , I am going to show you how httpd restarts their services in idempotence nature.

We can restart the httpd service in an idempotence nature.

Idempotence: Idempotence means that applying an operation once or applying it multiple times has the same effect. Examples: Multiplication by zero. No matter how many times you do it, the result is still zero.

When we make any changes to configuration files then only we restart any service. If we are executing a command to restart the service it will consume compute resources.

When we run ansible-playbook for restarting the service of httpd. It will again restart the service at the target node but I want the service to only restart when I make any change to configuration files otherwise it will not restart the service of httpd and save the compute resources.

For achieving the idempotence we will use the handler module and notify task in ansible.

notify :

List of handlers to notify when the task returns a ‘changed=True’ status.

handlers module in ansible :

Sometimes we want a task to run only when a change is made on a machine. For example, We 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.

I have written the playbook for this giving example :

I use “myvar.yml” file for storing value of variable .

“sourav.conf” file is responsible for changing port no and documentroot dynamically.

output :

Let’s check through chrome…

Here notify keyword will notify the handler when any change in the configuration file so that time only the httpd service restart otherwise it will not start the httpd service.

Thank you for reading my article😃

Keep Learning💯 Keep Sharing😇

--

--

Sourav Dinda
Sourav Dinda

No responses yet