HTTPD Service is not Idempotent in Nature — Make it using Ansible

Image for post

Agenda of this article:

HTTPD Service is not idempotent in nature and also consume more resources . So, lets figure out a way to make it idempotent in nature using Automation tool Ansible.

What is Ansible?

Image for post

Ansible is an open-source automation tool or platform used for in It sector for tasks such as configuration management, application deployment, orchestration, provisioning . Ansible is agentless, temporarily connecting remotely via SSH to do its tasks.

What is Apache Web Server?

Image for post

Apache is an open-source and free web server software that powers around 40% of websites around the world. The official name is Apache HTTP Server, and it’s maintained and developed by the Apache Software Foundation.

What is Idempotence nature of ansible?

Image for post

In general, idempotence is “the property of certain operations in mathematics and computer science that can be applied multiple times without changing the result beyond the initial application.

Hence, the principle that enables Ansible to be declarative and yet reliable is Idempotence.

Pre-requisits for this task:

Two RedHat Linux virtual machines on your system (Yum Configured).
1. Controller Node
2. Managed Node

Lets start the task:

  1. To check the Ansible version in Controller Node:
Image for post

2. Ansible has the entry of target nodes in its Inventory file:

Image for post

3. Command to re-check the number of Target Nodes in the inventory file:

Image for post

4. Command to check the connection with Managed Nodes :

Image for post

5. Now, our system is Configured.

We use YAML language to write plays in Ansible Playbook.

The Playbook we are going to use to configure HTTPD Web-server is as follows:

Image for post

Here, as you can see in this Playbook I have used Handlers keyword before Service Module.

What are Handers?

Handlers are just like normal tasks in Ansible Playbook but they execute only when the task contains notify directive. It indicates that something has been changed in the task.

So, after starting the HTTPD services once, if we try to restart the service again without modifying the Index file of Web Server, service will not be restarted.

HTTPD service will be restarted only when index file is modified. This saves the Server from restarting again and again and also saves Resources.

6. Now, lets start the services:

Image for post
Image for post

Now, as you can see Web Server has been configured successfully..!

Image for post

Now, If we try to restart the HTTPD service again, Handlers will not execute and hence service will not be restarted as the index file of the Server has not been modified.

Image for post

Now, lets modify the index file of the Web Server before restarting services.

Image for post

Re-starting HTTPD service:

Image for post

Now, as you can see HTTPD service has been restarted as the index file was modified.

Image for post

Hence, It proves that HTTPD service can be made Idempotent in nature using Handlers in Ansible.

Thank you..!

Hope you learnt something new 🙂



Categories: Ansible, automation, DevOps, Linux

Tags: , , , ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: