Making the HTTPD service Idempotent using Ansible | Task-11.3 | Arth |
What is Idempotence
By Idempotence nature we mean a task only happen when there is a need.
Whenever we run our ansible file with service module we can do two type of operation either start every time or when the service is not started.
But if our requirement is that whenever there some changes occur in the code file then the httpd services restart.
In this case the above feature is called Idempotence nature.
Task-deascription
Restarting HTTPD Service is not idempotence in nature and also consume more resources suggest a way to rectify this challenge in Ansible playbook.
Task-Steps
There is only one step to achieve Idempotence & that is use of Handlers module with service module. We set notify module with template task so that if any changes occur there the service task run.
Now let’s run this play-book.
You can see there 3 changes occur & as template task run the handler task also run.
Now i haven’t change anything, let’s run this play-book again.
You can see there no change occur and even handler task also didn’t run.
Let’s see our webserver working or not.
Now let me do some change in the file & then run this play-book.
Here we can see two changes occur. Let see the webserver to confirm we are in right direction or not.
So the website changes it’s content & we achieve idempotence.
!!!Thanks For Reading The Article!!!