🔰 Restarting HTTPD Service is not idempotence in nature and also consume more resources suggest a way to rectify this challenge in Ansible playbook.

🔰 Restarting HTTPD Service is not idempotence in nature and also consume more resources suggest a way to rectify this challenge in Ansible playbook.

Task Description

Restarting HTTPD Service is not idempotence in nature and also consume more resources suggest a way to rectify this challenge in Ansible playbook.

For this task both managed node and controller node are setup on RHEL 8.

  1. Choose the managed node.

No alt text provided for this image

2. Add the ip address of the managed node in the inventory.

No alt text provided for this image

3. Create the ansible playbook in the controller node.

4. Modules used for this task.

  • copy - Copies files to remote locations , The copy module copies a file from the local or remote machine to a location on the remote machine.
  • package - module is used to install the software on the managed node.
  • service - Controls services on remote hosts. Supported init systems include BSD init, OpenRC, SysV, Solaris SMF, systemd, upstart. For Windows targets, use the win_service module instead.

ANSIBLE CODE

No alt text provided for this image

  • In this task we want to run service only when a change is made on copy module. Handlers are tasks that only run when notified. Each handler should have a globally unique name.
  • Therefore the httpd services gets restart only when change is made in copy module.

5. If you run the ansible playbook first time.

No alt text provided for this image

The yellow color indicates that modules are executed.

6. As web pages are copied in the document root and also the web services are started in the managed node.

No alt text provided for this image

7. If we try to run again the ansible playbook .

No alt text provided for this image

This time we can see that green color appears this shows webservices are not restarted.

Thank you.

Tharakaram Dasari

Looking for new opportunities in Germany Site Reliability Engineer II @ JP Morgan Chase. @IUDX, @IISC

4y

Grt👏👏✨

Like
Reply

To view or add a comment, sign in

More articles by Ayush Bhat

Insights from the community

Others also viewed

Explore topics