Turning HTTPD into Idempotent via Ansible
What is Idempotency ?
An idempotent operation is one, which can be applied multiple times without changing the result beyond the initial application
Ansible modules are idempotent.
The HTTPD service should be restarted only when there are changes to be made in its configuration, Restarting a service each time we run a playbook could be an ineffective method. So to work around it we can use Handlers .
Handlers
These are similar to normal tasks in an Ansible playbook, but they run only when if the Task contains a “notify” directive. It also indicates that it changed tosomething.
Problem Statement:
🔹Restarting HTTPD Service is not idempotence in nature and also consume more resources. Suggest a way to rectify this challenge in the Ansible playbook.
Playbook:
My managed nodes:
Outcome of the playbook:
Now that the handler is notified , the hsts config has been updated
If we run the playbook again to test its idempotence :
Now, we’ve configured the HTTPD service using Ansible and also made it Idempotent in nature
Thank you for the time~!