Making "Restarting a service"? idempotent using Handlers in Ansible.

Making "Restarting a service" idempotent using Handlers in Ansible.

Restarting HTTPD Service is not idempotance in nature and also consume more resources so everytime we execute a playbook which has a service that stated as restart so it is quite expensive in terms of computational resource and time and both these things plays a decent role in a organization development and reputation in market.

No alt text provided for this image

Even though nothing is changed, the task of restarting the service executes everytime we execute the playbook.

No alt text provided for this image

So to avoid the extra expense of computational resource and save time we need to make the restart service idempotent in nature as well.

In ansible restarting a service is not idempotent but it provides a way to do so.

notify : it triggers a handlers

handler : It contains general tasks but these tasks executes only if someone triggers it. and to do so we use "notify"

In this case of restarting a service we can use the concept of handlers i.e put the restart task inside the handler and put the notify at the task after which there is a requirement to restart the service.

The Image below shows how to apply handlers.

No alt text provided for this image

here is the execution of playbook after adding handler.

No alt text provided for this image

that's it we make the restarting service Idempotent in nature.

要查看或添加评论,请登录

Anurag Vashishth的更多文章

社区洞察

其他会员也浏览了