<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">handlers</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2.2.1.0"><pre class="notranslate"><code class="notranslate">2.2.1.0
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Handlers with include statement are called multipled times (as many times as notify).</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: Testing notify handler with include
  hosts: blue
  become: True
  tasks:
    - command: id
      notify: restart test
    - command: id
      notify: restart test
    - command: id
      notify: restart test
    - command: id
      notify: restart test
  handlers:
    - name: restart test
      include: tasks/restart_test.yml"><pre class="notranslate"><code class="notranslate">- name: Testing notify handler with include
  hosts: blue
  become: True
  tasks:
    - command: id
      notify: restart test
    - command: id
      notify: restart test
    - command: id
      notify: restart test
    - command: id
      notify: restart test
  handlers:
    - name: restart test
      include: tasks/restart_test.yml
</code></pre></div>
<p dir="auto">And the restart_test.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: Restart test (we use NTP)
  service: name=ntp state=restarted"><pre class="notranslate"><code class="notranslate">- name: Restart test (we use NTP)
  service: name=ntp state=restarted
</code></pre></div>
<p dir="auto">Output</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook test-restart.yml

PLAY [Testing notify handler with include] *************************************

TASK [setup] *******************************************************************
ok: [host01]

TASK [command] *****************************************************************
changed: [host01]

TASK [command] *****************************************************************
changed: [host01]

TASK [command] *****************************************************************
changed: [host01]

TASK [command] *****************************************************************
changed: [host01]

RUNNING HANDLER [Restart test (we use NTP)] ************************************
changed: [host01]
changed: [host01]
changed: [host01]
changed: [host01]

PLAY RECAP *********************************************************************
host01                     : ok=9    changed=8    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">ansible-playbook test-restart.yml

PLAY [Testing notify handler with include] *************************************

TASK [setup] *******************************************************************
ok: [host01]

TASK [command] *****************************************************************
changed: [host01]

TASK [command] *****************************************************************
changed: [host01]

TASK [command] *****************************************************************
changed: [host01]

TASK [command] *****************************************************************
changed: [host01]

RUNNING HANDLER [Restart test (we use NTP)] ************************************
changed: [host01]
changed: [host01]
changed: [host01]
changed: [host01]

PLAY RECAP *********************************************************************
host01                     : ok=9    changed=8    unreachable=0    failed=0
</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">Handler should be executed only once.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">Handler being call as many times as notify</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">handlers</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.0.0
  config file = /home/duck/project/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.2.0.0
  config file = /home/duck/project/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<p dir="auto">This is RC2.</p>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">only the roles path is modified.</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Running on Debian unstable and managing CentOS 7.</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">To chain multiple actions in a handler I include a file, and this leads to the handler being fired multiple times.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">I used an include as suggested workaround for <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="130762955" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/14270" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/14270/hovercard" href="https://github.com/ansible/ansible/issues/14270">#14270</a>.</p>
<p dir="auto">My handler defined in handlers/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: restart networkd
  include: apply_config.yml"><pre class="notranslate"><code class="notranslate">- name: restart networkd
  include: apply_config.yml
</code></pre></div>
<p dir="auto">The apply_config.yml file contains:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: reboot
  # workaround for https://github.com/ansible/ansible/issues/14413
  shell: &quot;nohup bash -c 'sleep 2 &amp;&amp; shutdown -r now' &amp;&quot;
  async: 0
  poll: 0
  ignore_errors: true

- name: waiting for server to be up
  local_action:
    module: wait_for
    host: &quot;{{ ansible_host | default(inventory_hostname) }}&quot;
    port: 22
    state: started
    delay: 5
    timeout: 600
  become: no

# ensure the facts are updated
- setup:"><pre class="notranslate"><code class="notranslate">- name: reboot
  # workaround for https://github.com/ansible/ansible/issues/14413
  shell: "nohup bash -c 'sleep 2 &amp;&amp; shutdown -r now' &amp;"
  async: 0
  poll: 0
  ignore_errors: true

- name: waiting for server to be up
  local_action:
    module: wait_for
    host: "{{ ansible_host | default(inventory_hostname) }}"
    port: 22
    state: started
    delay: 5
    timeout: 600
  become: no

# ensure the facts are updated
- setup:
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Several changes (during roles tasks) call this trigger, but it should only be executed once.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">As you can see it is executed 5 times and breaks playbook execution:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK [networkd : enable networkd] **********************************************
changed: [myhost.mydom.tld]

RUNNING HANDLER [networkd : reboot] ********************************************
fatal: [myhost.mydom.tld]: UNREACHABLE! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh&quot;, &quot;unreachable&quot;: true}
fatal: [myhost.mydom.tld]: UNREACHABLE! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh&quot;, &quot;unreachable&quot;: true}
fatal: [myhost.mydom.tld]: UNREACHABLE! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh&quot;, &quot;unreachable&quot;: true}
changed: [myhost.mydom.tld]
fatal: [myhost.mydom.tld]: UNREACHABLE! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh&quot;, &quot;unreachable&quot;: true}

RUNNING HANDLER [networkd : waiting for server to be up] ***********************
ok: [myhost.mydom.tld -&gt; 192.168.57.10]
ok: [myhost.mydom.tld -&gt; 192.168.57.10]
ok: [myhost.mydom.tld -&gt; 192.168.57.10]
ok: [myhost.mydom.tld -&gt; 192.168.57.10]
ok: [myhost.mydom.tld -&gt; 192.168.57.10]

RUNNING HANDLER [networkd : setup] *********************************************
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
        to retry, use: --limit @/home/duck/OSAS/community-cage-infra-ansible/playbooks/deploy.retry"><pre class="notranslate"><code class="notranslate">TASK [networkd : enable networkd] **********************************************
changed: [myhost.mydom.tld]

RUNNING HANDLER [networkd : reboot] ********************************************
fatal: [myhost.mydom.tld]: UNREACHABLE! =&gt; {"changed": false, "msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}
fatal: [myhost.mydom.tld]: UNREACHABLE! =&gt; {"changed": false, "msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}
fatal: [myhost.mydom.tld]: UNREACHABLE! =&gt; {"changed": false, "msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}
changed: [myhost.mydom.tld]
fatal: [myhost.mydom.tld]: UNREACHABLE! =&gt; {"changed": false, "msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}

RUNNING HANDLER [networkd : waiting for server to be up] ***********************
ok: [myhost.mydom.tld -&gt; 192.168.57.10]
ok: [myhost.mydom.tld -&gt; 192.168.57.10]
ok: [myhost.mydom.tld -&gt; 192.168.57.10]
ok: [myhost.mydom.tld -&gt; 192.168.57.10]
ok: [myhost.mydom.tld -&gt; 192.168.57.10]

RUNNING HANDLER [networkd : setup] *********************************************
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
        to retry, use: --limit @/home/duck/OSAS/community-cage-infra-ansible/playbooks/deploy.retry
</code></pre></div>