Ansible Handlers

From rbachwiki
Revision as of 18:06, 14 July 2022 by Bacchas (talk | contribs)
Jump to navigation Jump to search

Handlers

  • Handlers are executed at the end of the play once all tasks are finished. In Ansible, handlers are typically used to start, reload, restart, and stop services.
---
- name: Verify apache installation
  hosts: localhost
  tasks:
  - name: Ensure apache is at the latest version
    yum:
     name: httpd
     state: latest

  - name: Copy updated apache config file
    copy:
     src: /tmp/httpd.conf
     dest: /etc/httpd.conf
    notify:
    - Restart apache
 
  - name: Ensure apache is running
    service:
     name: httpd
     state: started

  handlers:
    - name: Restart apache
      service:
       name: httpd
       state: restarted


Ansible Menu