Restarting HTTPD Service is not idempotence in nature and also consume more resources suggest a way to rectify this challenge in Ansible playbook
So lets Start
For doing this Task first lets check the configuration and the inventory file
cat /etc/ansible/ansible.cfg
Now lets check the ip.txt file and update the IP and credentials of the managed node
cat /root/ip.txt
Now check the connectivity using ping module
ansible web -m ping
Now we can write the playbook for httpd webserver configuration and as we will restart the services, it won’t be idempotence in nature. So, to resolve this we can use the register command and when command
“register” will store the data in any variable let’s say x and further we can check that data whether the change==false or change==true and we can use that variable in “when” command to run or skip that step according to the previous step.
you can download the code from here: Click here
Now if I’ll run the ansible-playbook command
ansible-playbook httpd.yml
Here the code changed so the service got restarted and the webserver got configured
But If I will run the ansible-playbook again, so because of its idempotence nature, the “restart service” step will skip and save our resources.
Done!!
I hope it was helpful