Making HTTPD Service Idempotent
Yash Dwivedi
RHCA | Quantum Computing | OpenShift | DevSecOps | DevOps | MLOps | Big Data | Hybrid Multi Cloud | AWS | GCP | Python | Terraform | Ansible | Kubernetes | MongoDB | GIT & GitHub
Description:
Restarting HTTPD Service is not idempotence in nature and also consume more resources suggest a way to rectify this challenge in Ansible playbook.
Solution:
We can use handlers and some keywords like changed_when or failed_when to make some of the tasks idempotent, and there I used handlers.
- hosts: web tasks: - name: Installing Pkg yum: name: httpd state: latest register: output - name: Installing WebPages template: src: "/ws/httpd-temp.txt.j2" dest: "/var/www/html/index.html" notify: Restarting httpd Service handlers: - name: Restarting httpd Service service: name: "httpd" state: restarted
The code of handlers would be look like this as above we can see, at the time of changing code only if the code change of httpd or template module run then it will notify handler if something change by the code.
we can run playbook by this command
#ansible-playbook code.yml
Thank You!!