✍TO MAKING OUR HTTPD SERVICES IPEMPOTENCE USING ANSIBLE PLAYBOOK :

Priya Soni
5 min readMar 21, 2021

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 :

  1. Setting up httpd webserver over Managed Node.
  2. Adding configuration files
  3. 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

inventory file

👉STEP 2 :

Now, We Configure the ansible configuration file.

# vim /etc/ansible/ansible.cfg

# cat /etc/ansible/ansible.cfg

configuration file

👉STEP 3 :

For Creating the ansible playbook.

# cd TASK11

# ls

# vim TASK11.3.yml

vim TASK11.3.yml

👉NEXT :

TASK11.3.yml

👉STEP 4 :

To Create a configuration file for the configuring webserver.

# vim web.conf

# cat web.conf

config file

👉STEP 5 :

To Check the connectivity to the Managed Node.

# ansible — version

for checking the ansible — version

👉NEXT :

# ansible all — list-hosts

for listing all the hosts

👉NEXT :

# ansible all -m ping

To ping the hosts

👉STEP 6 :

For checking the syntax of the ansible playbook.

# ansible-playbook — syntax-check TASK11.3.yml

for checking the syntax of our ansible playbook

👉STEP 7 :

For Executing the ansible playbook.

# ansible-playbook TASK11.3.yml

for running our ansible playbook

👉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

httpd is installed successfully

For checking the status of httpd services.

# systemctl status httpd

status of httpd services

✍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.

👉STEP 9:

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.

for running our ansible playbook again

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.

THANK YOU🙏🙏 GUYS FOR READING MY BLOG…

KEEP LEARNING🙇‍♂️📖🙇….

KEEP SHARING✌✌….

--

--