<p dir="auto">Hi,</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">include_role</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.1.0
  config file = /home/stephane/.ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.2.1.0
  config file = /home/stephane/.ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">Nothing special</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">Ansible running from ArchLinux, managing an OpenBSD machine, but the problem is with any managed machine.</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">When the include_role module is used within an handler, the calling role fails, before knowing if the handler will be called.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Create the simple following role:</p>

<p dir="auto">calling-role/tasks/main.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
- name: task with notify
  debug: msg=&quot;test&quot;"><pre class="notranslate">---
- <span class="pl-ent">name</span>: <span class="pl-s">task with notify</span>
  <span class="pl-ent">debug</span>: <span class="pl-s">msg="test"</span></pre></div>
<p dir="auto">calling-role/handlers/main.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
- name: handler
  include_role: name=called-role"><pre class="notranslate">---
- <span class="pl-ent">name</span>: <span class="pl-s">handler</span>
  <span class="pl-ent">include_role</span>: <span class="pl-s">name=called-role</span></pre></div>
<p dir="auto">called-role can be any role, with at least on task.</p>
<p dir="auto">I run this role with this playbook:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
- hosts:
    - all
  roles:
    - calling-role"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>:
    - <span class="pl-s">all</span>
  <span class="pl-ent">roles</span>:
    - <span class="pl-s">calling-role</span></pre></div>

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

<p dir="auto">I expect the playbook to run.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">The playbook doesn't run, it fails immediately.</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Using /home/stephane/.ansible.cfg as config file

PLAYBOOK: main.yml *************************************************************
1 plays in main.yml

PLAY [all] *********************************************************************
ERROR! Unexpected Exception: 'Task' object has no attribute 'listen'
the full traceback was:

Traceback (most recent call last):
  File &quot;/usr/bin/ansible-playbook&quot;, line 103, in &lt;module&gt;
    exit_code = cli.run()
  File &quot;/usr/lib/python2.7/site-packages/ansible/cli/playbook.py&quot;, line 159, in run
    results = pbex.run()
  File &quot;/usr/lib/python2.7/site-packages/ansible/executor/playbook_executor.py&quot;, line 154, in run
    result = self._tqm.run(play=play)
  File &quot;/usr/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py&quot;, line 248, in run
    self._initialize_notified_handlers(new_play)
  File &quot;/usr/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py&quot;, line 143, in _initialize_notified_handlers
    if handler.listen:
AttributeError: 'Task' object has no attribute 'listen'
zsh: exit 250   ansible-playbook main.yml -vvv"><pre class="notranslate"><code class="notranslate">Using /home/stephane/.ansible.cfg as config file

PLAYBOOK: main.yml *************************************************************
1 plays in main.yml

PLAY [all] *********************************************************************
ERROR! Unexpected Exception: 'Task' object has no attribute 'listen'
the full traceback was:

Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 103, in &lt;module&gt;
    exit_code = cli.run()
  File "/usr/lib/python2.7/site-packages/ansible/cli/playbook.py", line 159, in run
    results = pbex.run()
  File "/usr/lib/python2.7/site-packages/ansible/executor/playbook_executor.py", line 154, in run
    result = self._tqm.run(play=play)
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 248, in run
    self._initialize_notified_handlers(new_play)
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 143, in _initialize_notified_handlers
    if handler.listen:
AttributeError: 'Task' object has no attribute 'listen'
zsh: exit 250   ansible-playbook main.yml -vvv
</code></pre></div>
<p dir="auto">The problem still exists with the devel branch (216e2c8).</p>
<p dir="auto">Let me know if I can be of any help concerning this issue!</p>
<p dir="auto">Stéphane</p>
<h5 dir="auto">ISSUE TYPE</h5>

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

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

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.1.2.0
  config file = 
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.1.2.0
  config file = 
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Ubunty 16.04, created irtual environment with pip install ansible</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Error handling/displaying not working in loops properly</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: Install packages
  yum:
    name: &quot;{{ item }}&quot;
    state: present
  with_items:
    - non-existing-package
"><pre class="notranslate"><code class="notranslate">- name: Install packages
  yum:
    name: "{{ item }}"
    state: present
  with_items:
    - non-existing-package

</code></pre></div>

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

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

TASK [install packages] ********************************************************
failed: [test] (item=non-existing-package) =&gt; {&quot;changed&quot;: false, &quot;failed&quot;: true, &quot;item&quot;: &quot;non-existing-package&quot;, &quot;msg&quot;: &quot;No Package matching 'non-existing-package' found available, installed or updated&quot;, &quot;rc&quot;: 0, results: []}

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @test.retry

PLAY RECAP *********************************************************************
test                       : ok=0    changed=0    unreachable=0    failed=1   
"><pre class="notranslate"><code class="notranslate">PLAY [test playbook] ***********************************************************

TASK [install packages] ********************************************************
failed: [test] (item=non-existing-package) =&gt; {"changed": false, "failed": true, "item": "non-existing-package", "msg": "No Package matching 'non-existing-package' found available, installed or updated", "rc": 0, results: []}

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @test.retry

PLAY RECAP *********************************************************************
test                       : ok=0    changed=0    unreachable=0    failed=1   

</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>

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

TASK [install packages] ********************************************************
ok: [test] =&gt; (item=[u'non-existing-package'])

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @test.retry

PLAY RECAP *********************************************************************
test                       : ok=0    changed=0    unreachable=0    failed=1   "><pre class="notranslate"><code class="notranslate">PLAY [test playbook] ***********************************************************

TASK [install packages] ********************************************************
ok: [test] =&gt; (item=[u'non-existing-package'])

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @test.retry

PLAY RECAP *********************************************************************
test                       : ok=0    changed=0    unreachable=0    failed=1   
</code></pre></div>
<p dir="auto">I've dig a little bit into this issue, and I've found, that if a result key is exists in the returned dictionary (even if it's empty array), the display will be ok:<br>
If I delete the the result from dict, It's working fine (res.pop('result', None) in yum.py</p>
<p dir="auto">If I run the command directly (without loop), it displays it correctly</p>