Ansible Idempotence

Ansible Idempotence


ANSIBLE WITH HANDLER

  • Published on December 8, 2020


Gourav Gopal Terwadkar

Arth-learner |

No alt text provided for this image


#11.3Restarting HTTPD Service is not idempotence in nature and also consume more resources suggest a way to rectify this challenge in Ansible playbook.

 

Sometimes you want a task to run only when a change is made on a machine. For example, you 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. Each handler should have a globally unique name.

Now we have a YAML code here without using handler in that code. So, when we run that code first time httpd service restart on manage node according to our code .

As we know ,if we change something on configuration file then we need to restart service again but if we don’t make any change in configure file then we don’t need to restart service .

 But we know ansible is idempotent in nature means if something is already install or service is started then ansible skip that part of code for doing it again.

 In this below code ,if you run this ansible playbook again then it will again restart the service which is inappropriate or resolve this issue Ansible uses Handler to address this use case. Handler are tasks that only run when notified.

 

Now , I make changes in YAML code by using handler inside it .

So, if we use this ansible playbook second time then this code never restart service every time until we makes changes on configure file .

 SO, HERE TASK 11.3 IS COMPLETED SUCCEWSSFULLY..

THANKU FOR READING THIS ARTICLE GUYS!!


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

社区洞察

其他会员也浏览了