Making Apache2 Idempotent Using Ansible

What is Ansible?

Ansible is open source automation tool mostly used for configuration management . It is agentless program we just have to install Ansible and python on master node we doesn’t require any software on controller nodes. Nodes can be any machine windows,mac,Linux ,anything.

What is Apache2?

Apache2 also known as httpd software . It is open source webserver used as HTTP server. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.


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-

Here I’ve used handlers concept to solve this task. It is triggered when notify keyword notifies it to run.In above playbook which is written in yaml language it first install httpd software , Enables firewall on port 80 becuase http service run on port 80 , starts server and insert web page in controller node with content and then used handler to restart service and it also helps in making it idempotent.


I’ve run this playbook on localhost for testing (we can also use same for remote server).

As you can see here yellow notifies that it is changed. (In my httpd is already installed and firewall was configured so it showing green otherwise it can be in yellow). After starting httpd content of webpage is inserted so it notified handler and handler restarted httpd service.

Output After again we run same service:

As you can see now all tasks are showing in green and restarting httpd is not there. We doesn’t changed anything inside html code task so it doesn’t run handler. Using this concept httpd idempotence is achieved.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store