Making HTTPD Service Idempotent

Making HTTPD Service Idempotent

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


No alt text provided for this image

Thank You!!

要查看或添加评论,请登录

Yash Dwivedi的更多文章

社区洞察

其他会员也浏览了