Restarting HTTPD Service Is Not Idempotence In Nature Using Ansible Playbook ?????

Restarting HTTPD Service Is Not Idempotence In Nature Using Ansible Playbook ????

No alt text provided for this image

Task Description??


?? 11.3 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 Ansible?

Ansible is a software tool that provides simple but powerful automation for cross-platform computer support. It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis. Ansible doesn't depend on agent software and has no additional security infrastructure, so it's easy to deploy.

How Ansible works :

Ansible works by connecting to nodes (clients, servers, or whatever you're configuring) on a network, and then sending a small program called an Ansible module to that node. Ansible executes these modules over SSH and removes them when finished. The only requirement for this interaction is that your Ansible control node has login access to the managed nodes. SSH Keys are the most common way to provide access, but other forms of authentication are also supported

What is idempotence???

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”. For Ansible it means after 1 run of a playbook to set things to a desired state, further runs of the same playbook should result in 0 changes. But "restarting httpd service" is not idempotence in nature

When we need to restart httpd services???

When ever we make some changes in httpd configuration file then we need to restart the services. But we can add one more section name "handlers" which contains task, that would be executed only and only when it is notified.

Handlers :

Sometimes you want a task to run only when a change is made on a machine. For example, you may want to restart a service if a task updates the configuration of that service, but not if the configuration is unchanged. Ansible uses handlers to address this use case. Handlers are tasks that only run when notified. Each handler should have a globally unique name. For triggering handler we need to use notify directive.

Basically when ever any changes are made it will notify handler and hence handler's task would be executed.

Pre-requisites:

  • * Controller Node
  • * Managed Node

But if you don't have so many system so you can use controller as a managed also for that you have to use localhost at the place of host_ip in the ansible playbook .

so here I have use controller node as a managed node also....

So let's Start ......

Ansible tool work on the python thus to install the ansible we have to use the pip3 command

command : pip3 install ansible

Then we have check weather the Ansible is install or not .For checking

command : ansible --version

No alt text provided for this image

Now we have to go at managed node.. and check the IP of the managed node . When we can get the IP of managed node then go to the controller node and create the inventory file . After that create the configuration file by using the command

command : " vim /etc/ansible/"name_of_file".cfg "

No alt text provided for this image

Now lets see the playbook :

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Now lets see the var file , where we stored all the vars used in the playbook.

No alt text provided for this image

Now check the syntax of the main playbook ansible-playbook --syntax-check file_name.yml and after that run this playbook by typing ansible-playbook file_name.yml. It will give the output like this.

No alt text provided for this image
No alt text provided for this image

Here we can see that playbook run without any error .

Now i am going to the manage nodes and see the configuration , whatever we have did in the playbook.

No alt text provided for this image

 Here You can see port number is listening and the httpd software is successfully installed.

Now i am going to the web-browser and check the webpage , that is i am copying from the os to manage hosts.

No alt text provided for this image

Now If you run the playbook again then it will shows that Your service is started so no need the restart again this become possible because of the handlers and notify keyworks in ansible.

Now I change my var file where I store the variables.

No alt text provided for this image

Lets run the playbook again and see what happen ?

No alt text provided for this image
No alt text provided for this image

Here you can see my handler module is working properly . After that lets check the new_port number is working or not

No alt text provided for this image

You can see here port number is listening and working great..

Now i am going to the web-browser to check the webpages coming or not.

You can check the final output from the browser and type both the port number but at this time port number 8025 is not working but if you can see the port number 8002 then it is working properly

No alt text provided for this image

And finally Task completed successfully...

Thanks for reading .....!!!

Thank you Mr. Vimal Daga sir for this great task ..!!!

Sai Teja Chowdhary K

Infra Transformation Analyst | Azure Data Engineer | DevOps Enthusiast

4 年

Great work

Nilesh Gopale

MTS 1 @Cohesity | Ex-Veritas | Kubernetes | Docker | Golang | Python

4 年

Great work Anushka ???

要查看或添加评论,请登录

Anushka Visapure的更多文章

社区洞察

其他会员也浏览了