Skip to content
Ansible

icon picker
Handlers in ansible

Handlers are used to solve dependency in ansible, if we want one task to run only if there is some change in another task then in such cases we can use handler

- name: Installing WebServer
hosts: all
remote_user: ec2-user
become: 'yes'
become_user: root

tasks:
- name: Ensure Apache is at the Latest Version
yum:
name: httpd
state: present
notify:
- Ensure Apache is Running
- Ensure Apache restart

handlers:
- name: Ensure Apache is Running
service:
name: httpd
state: started

- name: Ensure Apache restart
service:
name: httpd
state: restarted
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.