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?
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?
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?
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:
- To check the Ansible version in Controller Node:
2. Ansible has the entry of target nodes in its Inventory file:
3. Command to re-check the number of Target Nodes in the inventory file:
4. Command to check the connection with Managed Nodes :
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:
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:
Now, as you can see Web Server has been configured successfully..!
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.
Now, lets modify the index file of the Web Server before restarting services.
Re-starting HTTPD service:
Now, as you can see HTTPD service has been restarted as the index file was modified.