Difference between revisions of "Ansible Handlers"

From rbachwiki
Jump to navigation Jump to search
(Created page with "= 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. = Ansible Menu= Category:Ansible")
 
Line 1: Line 1:
= Handlers=
= 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.
*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.
<pre>
---
- 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
</pre>


=[[Ansible| Ansible Menu]]=
=[[Ansible| Ansible Menu]]=
[[Category:Ansible]]
[[Category:Ansible]]

Revision as of 18:06, 14 July 2022

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