DEV Community

loading...
Cover image for How to make HTTPD Service idempotence in Nature using Ansible?

How to make HTTPD Service idempotence in Nature using Ansible?

Nitesh Thapliyal
I'm an Information technology student. I'm passionate about current and emerging technologies. I have always been fascinated by how things work, functionality, and problem-solving.
・2 min read

Hello everyone,

In this blog, we are going to solve one problem and that problem is "Restarting HTTPD Service is not idempotence in nature and also consume more resources"

So let's solve this problem:

The task that we are going to perform in this blog are:

  • Create an Ansible playbook to configure yum in the managed node.
  • Install apache webserver httpd in the managed node.
  • Configure the webserver.

My setup is something like thisπŸ‘‡

Alt Text

Now create an Inventory

Create an Inventory anywhere in the system, here I have created an inventory named ip.txt.

Alt Text

Now check the connectivity with Managed Node using the command ansible all -m ping

Alt Text

Now create an ansible configuration file.

Alt Text

Now create a configuration file for htttpd

Here I have created a configuration file named httpd.conf

Alt Text

Now Create an Ansible Playbook

Alt Text
Alt Text

In this playbook, we have configured yum, installed httpd, and configured it.

Now before running the playbook let's check in the managed node whether yum and httpd is configured already or not...

  • To check whether yum is configured or not use command yum repolist

Alt Text

Here you can it is not configured.

  • To check whether httpd is installed or not use command rpm-q httpd

Alt Text

Here you can see httpd is not installed

Now run the playbook

Alt Text

Alt Text

Here you can see the playbook run successfully....

Now check in the managed node, changes that we did using ansible are done or not.

  • let's check yum is configured or not, we can check that using command yum repolist

Alt Text

now you can see that it is configured successfully....

  • check httpd is installed or not, we can check that using command rpm -q httpd

Alt Text

Now you can see it is installed successfully....

  • check whether the configuration file is placed in managed node or not.

Alt Text

Here you can see httpd.conf that we created is placed and configured successfully...

Thank you..❄

Discussion (0)