Task 11.3 Description 📄:
✨ Restarting HTTPD Service is not idempotence in nature and also consume more resources suggest a way to rectify this challenge in Ansible playbook.
✍WHAT IS IDEMPOTENCE NATURE ?
It is a operation that can be applied multiple times without changing the output of previous state. In terms of HTTPD service understand it as :
A request method is considered idempotent if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request.
And it’s worthwhile to mention that idempotency is about the effect produced on the state of the resource on the server and not about the response status code received by the client.
👉So, In this task we are going to Configure a webserver on a Managed Node through an Ansible with the feature of Dynamic Updates.
👉OUR TASK MOTIVE :
- Setting up httpd webserver over Managed Node.
- Adding configuration files
- Handling the service, to be started only when there are some changes in the configurations.
👉So without wasting your time lets jump to our practical part implementation……
👉STEP 1 :
So, First step is to configure the inventory file.
# vim hosts.txt
👉STEP 2 :
Now, We Configure the ansible configuration file.
# vim /etc/ansible/ansible.cfg
# cat /etc/ansible/ansible.cfg
👉STEP 3 :
For Creating the ansible playbook.
# cd TASK11
# vim TASK11.3.yml
👉STEP 4 :
To Create a configuration file for the configuring webserver.
# vim web.conf
# cat web.conf
👉STEP 5 :
To Check the connectivity to the Managed Node.
# ansible — version
# ansible all — list-hosts
# ansible all -m ping
👉STEP 6 :
For checking the syntax of the ansible playbook.
# ansible-playbook — syntax-check TASK11.3.yml
👉STEP 7 :
For Executing the ansible playbook.
# ansible-playbook TASK11.3.yml
👉STEP 8 :
For Checking the Managed node is successfully configured or not?
So, we can check httpd is installed or not in our manged node.
# rpm -q httpd
For checking the status of httpd services.
# systemctl status httpd
✍FOR UNDERSTANDING THE HANDLERS :
Sometimes we want our task to run only when a change is made on a machine. For this use-cases Ansible uses handlers to address .
Handlers are tasks that only run when notified. Each handler should have a globally unique name.
Handlers are just like normal tasks in an Ansible playbook but they run only when if the Task contains a “notify” directive. It indicates that it changed something. And when any change is detected then it notifies the respective handler and the task completes.
So here, in the above code when we run the playbook, initially the configuration has changed so, it runs the handler and restart the service.
So Here We can try to execute the ansible playbook again.
But the next time when we run the same playbook, since the configuration is same it skips the notify directive and hence the handler is not called.
Finally I have successfully completed this task. Thank you Vimal Daga sir for giving me such a great task. Sir your mentorship is a God gift for me to enhance my skills and I am very blessed because you are my mentor.
So guys, In the upcoming days I am going to be publish a lots of blogs and articles on different different automation tools and other technologies, So definetely follow me on Medium as well as on linkedin.
So, Here is my linkedin profile if you have any queries definitely comment below or DM me on linkedin.
Priya Soni - Technical volunteer - ARTH - The School of Technologies | LinkedIn
" Success is not end but it still continue whenever we reach our future destination". Hii Friends, my name is Priya…