How to make Apache services idempotent using ansible?

About apache:

About ansible

What is idempotency in ansible?

Some prerequisite for the task:

  1. Ansible must be configured in “Controller Node”
  2. Ansible inventory must have the IP of the system which we will configure as a web server(i.e. Managed node).
  3. Managed Node must have YUM configured

Initially, Apache is not idempotent in nature. This makes apache use more memory and resources every time we run the ansible playbook to configure our web server on the managed node. Because every time we run the ansible playbook it will run the whole process from scratch as it is making it “non-idempotent’’. We can make apache idempotent by using handlers in our ansible playbook in the following manner.

What are Handlers in ansible?

In our case, “httpd” and firewall services will restart only if we will make any changes on the html file or in the ansible inventory.

The below image shows the following output, if we run the playbook after making some changes in any of the html file,

But , now if run the playbook again , this time already the file is present in the specific folder of managed node , so it won’t be copied due to idempotence nature of Ansible. Here no change is made so the handler is not notified , and hence “httpd” is not restarted.

Check out the GitHub to know more about the complete codes used to make apache idempotent: https://github.com/yashraj24/Making-apache-idempotent-using-ansible

Thank you for reading!!…

--

--

A B.tech undergrad, enthusiastic towards learning new technologies in the market and integrate the technologies with each other.

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
Yashraj Panda

A B.tech undergrad, enthusiastic towards learning new technologies in the market and integrate the technologies with each other.