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

<ul dir="auto">
<li>Bug Report</li>
</ul>
<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 (devel f9c4fdab40) last updated 2016/05/24 13:16:23 (GMT +200)
  lib/ansible/modules/core: (detached HEAD a64d72d7bc) last updated 2016/05/24 13:16:41 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD d2900e856b) last updated 2016/05/24 13:16:48 (GMT +200)
  config file =
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.2.0 (devel f9c4fdab40) last updated 2016/05/24 13:16:23 (GMT +200)
  lib/ansible/modules/core: (detached HEAD a64d72d7bc) last updated 2016/05/24 13:16:41 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD d2900e856b) last updated 2016/05/24 13:16:48 (GMT +200)
  config file =
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

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

<p dir="auto">Ubuntu 16.04</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">If a handler is notified, then even if the handler is missing the playbook completes successfully without errors or warnings.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- debug: msg=&quot;test handler&quot;
  changed_when: true
  notify:
    - nonexistent_handler"><pre class="notranslate"><code class="notranslate">- debug: msg="test handler"
  changed_when: true
  notify:
    - nonexistent_handler
</code></pre></div>
<p dir="auto">then run the playbook.</p>

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

<p dir="auto">PLAY RECAP , failed=1</p>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="NOTIFIED HANDLER nonexistent_handler
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;test handler&quot;
}

PLAY RECAP *********************************************************************
localhost                  : ok=12   changed=1    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">NOTIFIED HANDLER nonexistent_handler
ok: [localhost] =&gt; {
    "msg": "test handler"
}

PLAY RECAP *********************************************************************
localhost                  : ok=12   changed=1    unreachable=0    failed=0
</code></pre></div>
<h5 dir="auto">Issue Type:</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">Ansible Version:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="v2.0.1.0"><pre class="notranslate"><code class="notranslate">v2.0.1.0
</code></pre></div>
<h5 dir="auto">Ansible Configuration:</h5>

<p dir="auto">Nothing in particular.</p>
<h5 dir="auto">Summary:</h5>

<p dir="auto">When you run ansible-playbook on a set of tasks with handlers, the existence of the handler is not checked, but those handlers are silently ignored. Even when the task induced a change.</p>
<p dir="auto">Because of this, people may make mistakes in handlers but won't ever know that things aren't as they would expect. Ansible could test the existence of handler references and warn about them (when there's no change) and fail (when they are being called).</p>
<p dir="auto">Silently ignoring notification handlers that should/could be run is problematic.</p>
<h5 dir="auto">Steps To Reproduce:</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- hosts: localhost
  gather_facts: no
  handlers:
    - name: foo-bar
      debug: msg='Handler foo-bar ran'
  tasks:
    - name: 'Use an incorrect handler name, ansible-playbook does not care'
      command: 'true'
      changed_when: no
      notify:
        - foo_bar

    - command: 'true'
      notify:
        - bar-foo

    - command: 'true'
      notify:
        - foo-bar                                                                                                   "><pre class="notranslate"><code class="notranslate">- hosts: localhost
  gather_facts: no
  handlers:
    - name: foo-bar
      debug: msg='Handler foo-bar ran'
  tasks:
    - name: 'Use an incorrect handler name, ansible-playbook does not care'
      command: 'true'
      changed_when: no
      notify:
        - foo_bar

    - command: 'true'
      notify:
        - bar-foo

    - command: 'true'
      notify:
        - foo-bar                                                                                                   
</code></pre></div>

<h5 dir="auto">Expected Results:</h5>

<p dir="auto">Failure report about notification handlers that do not exist.</p>
<p dir="auto">This failure should happen also for handlers that are not to be used (i.e. because there was no change).</p>
<h5 dir="auto">Actual Results:</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY ***************************************************************************

TASK [Use an incorrect handler name, ansible-playbook does not care] ***********
ok: [localhost]

TASK [command] *****************************************************************
changed: [localhost]

TASK [command] *****************************************************************
changed: [localhost]

RUNNING HANDLER [foo-bar] ******************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;Handler foo-bar ran&quot;
}

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=2    unreachable=0    failed=0   "><pre class="notranslate"><code class="notranslate">PLAY ***************************************************************************

TASK [Use an incorrect handler name, ansible-playbook does not care] ***********
ok: [localhost]

TASK [command] *****************************************************************
changed: [localhost]

TASK [command] *****************************************************************
changed: [localhost]

RUNNING HANDLER [foo-bar] ******************************************************
ok: [localhost] =&gt; {
    "msg": "Handler foo-bar ran"
}

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=2    unreachable=0    failed=0   
</code></pre></div>
<p dir="auto">The first task (no change) and second task (change) should both report some failure because the notification handler does not exist. Silently ignoring this is a recipe for disaster !</p>