How to make services module of Ansible Idempotence in nature.

Abhishek Sahu
3 min readMar 23, 2021

Hello readers, Hope you all are doing well in this lockdown period. Today I bring a blog for you in which I will tell you, that how can you make your services Idempotence, So that every time you run your playbook it’s services won’t restarted again.

Source : https://sharmashristi532.medium.com/httpd-service-idempotence-nature-61fa00905b8b

So for this blog I am taking example of Apache Httpd server, It is conveys very bad impression when updating a minor bugs lets your webserver to be restarted. But When we use ansible playbook with service as a restarted option, every time the playbook runs it restarted the webserver, Which is not good thing for us.

To overcome from this issue, We guys are going to use handlers today, such that so whenever any major changes take place it only restart the playbook then only.

I am also attaching GitHub link for complete playbook here -

Creating Playbook
Playbook Containing handlers.
1st WebPage

Run the playbook using “ansible-playbbok webserver.yml” command.

Playbook Execution first time

When We run our playbook for very first time it started the webservice as the code is new for it. Let’s try to run the same playbook again.

Again running the same playbook.

Now you can see that This time our service hasn’t restarted for webserver. Let’s try exploring the website.

Web Result

Now Let’s run the same playbook after changing the webpage a little.

2nd Webpage.
Playbook

Now you can see that as the code changed the handler started working. So finally we achieved our goal of making ansible playbook idempotence in nature.

Thanks For reading this Small Blog, Hope you find it helpful.

--

--

Abhishek Sahu

Hey Readers, I am tech enthusiast and an Computer Science Student. Here I am sharing various industry use cases and its solution.