Restarting HTTPD Service is not idempotence in nature using Ansible playbook

Neha sonone
3 min readDec 20, 2020

What is Idempotence?

Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application. But restarting HTTPD service is not idempotence in nature, and also consumes more resources, so whenever we make changes in our file only then we want our service to restart not all the time restarting service can be helpful your way,

so for solving this challenge in the ansible-playbook we can use handlers for solving the challenge

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.

Let's start with the Practical…

  • first, you have to create a workspace
  • now check you have proper connectivity or not

we have connectivity to the target node, the green color is showing

  • here is my web.yml file
  • you have to install ansible.posix.selinux collection in the controller node
# ansible-galaxy collection install ansible.posix
  • the var.yml file where we have our variables
  • for checking the syntax of our ansible playbook we have command
  • run the playbook web.yml
  • now see in the target node what port is running and whether the file copied in the target node or not
  • so the port 8080 is there in the target node , check the index2.html file exists in the target node ,and the httpd is also installed.
  • now make changes in the var.yml file to change the port to 8089
  • and after doing the changes run the playbook again
  • and after the playbook run successfully check in the target node what port is running
  • now check the content which we have copied in the target node running properly or not

webpage is also running properly,

Thank you for reading

--

--