Chapter 11: Ansible Introduction
11.6 Handlers — restart only when needed
In short: Handler runs at end of play if notified — so a no-change copy does not reload Nginx every time.
tasks:
- name: Deploy nginx config snippet
ansible.builtin.copy:
src: files/badge-api.conf
dest: /etc/nginx/conf.d/badge-api.conf
mode: "0644"
notify: Reload nginx
handlers:
- name: Reload nginx
ansible.builtin.service:
name: nginx
state: reloaded
Handler runs at end of play if notified — so a no-change copy does not reload Nginx every time.