Restarting HTTPD Service is not idempotence in nature-Rectifying this challenge in Ansible Playbook..!!

Shrishti Kapoor
2 min readFeb 5, 2021

Before moving further to rectify First Lets see What is IDEMPOTENCE..!!

IDEMPOTANCE:

An operation is idempotent if the result of performing it once is exactly the same as the result of performing it repeatedly without any intervening actions. This means that If the user is looking for something and that is already there then skipping that command or code will help in saving time and cost.

There are various modules in ansible which supports idempotence but some don’t support this like for example restarting some services don’t support this which in return consumes lots of resources and time. So to overcome this challenge we use Handlers.

We want to restart a service if a task updates the configuration of that service, but not if the configuration is unchanged so for that Ansible uses handlers to address this use case.

Handlers are just like regular tasks in an Ansible playbook but only run if the Task contains a notify directive and also indicates that it changed something. Since a notification is required which help to skip that task as it is already started so for that handlers use notify keyword. If the Task contains a “notify” It indicates that it changed something.

By default, handlers run after all the tasks in a particular play have been completed. This approach is efficient, because the handler only runs once, regardless of how many tasks notify it. For example, if multiple tasks update a configuration file and notify a handler to restart Apache, Ansible only bounces Apache once to avoid unnecessary restarts.

So through this Video given below. The steps are demonstrated that Some services in ansible don’t support idempotence but to rectify that challenge Handlers are used. In this video both the ways are differentiated so that it can easily detect that what change does the handler do to rectify this challenge.

So through this Video it is pretty clear that some services in ansible are not idempotent but to solve this challenge some keywords like handlers can help is solving this Challenge..!!

--

--

Shrishti Kapoor

Spread Knowledge because it’s all about Right Education..!!