Make Restarting HTTPD Service idempotence

What is Idempotence?

Himanshu Agrawal

--

Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.

But restarting HTTPD service is not idempotence in nature, and also consumes more resources, so whenever we make changes in our file only then we want our service to restart not all the time restarting service can be helpful your way,

so for solving this challenge in the ansible-playbook we can use handlers for solving the challenge

Working with Ansible Handlers

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

Inventory File: /root/ip.txt

Ansible Configuration File : /etc/ansible/ansible.cfg

we will copy my.conf file in /etc/httpd/conf.d/

my.conf file:

playbook: apache.yml

handlers have the capability if you changed something, first, you need to notify it and after use in the name of a handler.

now run ansible playbook:

ansible-playbook apache.yml

When we changed port number than httpd configuration file “my.conf” will also change so Handler task will run.

We have done this task successfully

Thank you for reading

My LinkedIn: Himanshu Agrawal

--

--

No responses yet