Non-idempotent httpd

Krithika Sharma
2 min readJan 6, 2021
Restarting httpd service-idempotent in nature

Task Description:
đź”° 11.3 Restarting HTTPD Service is not idempotence in nature and also consume more resources suggest a way to rectify this challenge in Ansible playbook

Ansible playbook uses a declarative language approach and is idempotent in nature i.e., if some task is already done then it does not do it again! But this is not idempotent in the case of restarting the httpd service.

If it keeps on restarting the services again and again even tough the services are started, it will consume more resources and time and this is not a good for the users.

So, inorder to make this optimized, we will be using “when” keyword and “register”:

for the first time it restarts the services, then if run the playbook again this time it will not restart the services making it non-idempotent.

As we can see that the “starting services” task is skipped. Using register to register a task in a variable and using that registered value and doing another task based on when variable changed.

Task accomplished!!!

Thankyou! Keep learning! keep growing! Keep sharing!

--

--