title: Run an Ansible handler only once for the entire playbook
body: <p>I would like to run a handler only once in an entire playbook.</p>
  
  <p>I attempted using an include statement in the following in the playbook file, but this resulted in the handler being run multiple times, once for each play:</p>
  
  <pre><code>- name: Configure common config
    hosts: all
    become: true
    vars:
          OE: "{{ ansible_hostname[5] }}"
    roles:
      - { role: common }
    handlers:
      - include: handlers/main.yml
  
  - name: Configure metadata config
    hosts: metadata
    become: true
    vars:
          OE: "{{ ansible_hostname[5] }}"
    roles:
      - { role: metadata }
    handlers:
      - include: handlers/main.yml
  </code></pre>
  
  <p>Here is the content of handlers/main.yml:</p>
  
  <pre><code>- name: restart autofs
    service:
      name: autofs.service
      state: restarted
  </code></pre>
  
  <p>Here is an example of one of the tasks that notifies the handler:</p>
  
  <pre><code>- name: Configure automount - /opt/local/xxx in /etc/auto.direct
    lineinfile:
       dest: /etc/auto.direct
       regexp: "^/opt/local/xxx"
       line: "/opt/local/xxx   -acdirmin=0,acdirmax=0,rdirplus,rw,hard,intr,bg,retry=2  nfs_server:/vol/xxx"
    notify: restart autofs
  </code></pre>
  
  <p>How can I get the playbook to only execute the handler once for the entire playbook?</p>