# Buggy code
def get_block_list(self, play=None, variable_manager=None, loader=None):
    # only need play passed in when dynamic
    if play is None:
        myplay = self._parent._play
    else:
        myplay = play

    ri = RoleInclude.load(
        self._role_name, play=myplay, variable_manager=variable_manager, loader=loader
    )
    ri.vars.update(self.vars)

    # build role
    actual_role = Role.load(
        ri, myplay, parent_role=self._parent_role, from_files=self._from_files
    )
    actual_role._metadata.allow_duplicates = self.allow_duplicates

    # compile role with parent roles as dependencies to ensure they inherit
    # variables
    if not self._parent_role:
        dep_chain = []
    else:
        dep_chain = list(self._parent_role._parents)
        dep_chain.append(self._parent_role)

    blocks = actual_role.compile(play=myplay, dep_chain=dep_chain)
    for b in blocks:
        b._parent = self

    # updated available handlers in play
    myplay.handlers = myplay.handlers + actual_role.get_handler_blocks(play=myplay)

    return blocks


# Traceback (KeyError)
ansible-playbook -vvvv playbook.yml
No config file found; using defaults
[WARNING]: Host file not found: /etc/ansible/hosts

[WARNING]: provided hosts list is empty, only localhost is available

Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc

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

PLAY [localhost] ***************************************************************

TASK [include_role] ************************************************************
task path: /Users/xxx/workspace/xxx/playbook.yml:6

TASK [handlertest : command] ***************************************************
task path: /Users/xxx/workspace/xxx/roles/handlertest/tasks/main.yml:3
Using module file /usr/local/lib/python2.7/site-packages/ansible/modules/core/commands/command.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: xxx
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1478572148.78-187995060050975 `" &amp;&amp; echo ansible-tmp-1478572148.78-187995060050975="` echo $HOME/.ansible/tmp/ansible-tmp-1478572148.78-187995060050975 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /var/folders/62/pqgvprd11fb4k6shw2pdzkqm0000gq/T/tmpGA2Gau TO /Users/xxx/.ansible/tmp/ansible-tmp-1478572148.78-187995060050975/command.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /Users/xxx/.ansible/tmp/ansible-tmp-1478572148.78-187995060050975/ /Users/xxx/.ansible/tmp/ansible-tmp-1478572148.78-187995060050975/command.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/local/opt/python/bin/python2.7 /Users/xxx/.ansible/tmp/ansible-tmp-1478572148.78-187995060050975/command.py; rm -rf "/Users/xxx/.ansible/tmp/ansible-tmp-1478572148.78-187995060050975/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
ERROR! Unexpected Exception: HANDLER: handlertest : Some handler
the full traceback was:

Traceback (most recent call last):
File "/usr/local/bin/ansible-playbook", line 103, in <module>
exit_code = cli.run()
File "/usr/local/lib/python2.7/site-packages/ansible/cli/playbook.py", line 159, in run
results = pbex.run()
File "/usr/local/lib/python2.7/site-packages/ansible/executor/playbook_executor.py", line 154, in run
result = self._tqm.run(play=play)
File "/usr/local/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 282, in run
play_return = strategy.run(iterator, play_context)
File "/usr/local/lib/python2.7/site-packages/ansible/plugins/strategy/linear.py", line 278, in run
results += self._wait_on_pending_results(iterator)
File "/usr/local/lib/python2.7/site-packages/ansible/plugins/strategy/__init__.py", line 534, in _wait_on_pending_results
results = self._process_pending_results(iterator)
File "/usr/local/lib/python2.7/site-packages/ansible/plugins/strategy/__init__.py", line 399, in _process_pending_results
if original_host not in self._notified_handlers[target_handler]:
KeyError: HANDLER: handlertest : Some handler

# Fixed code
def get_block_list(self, play=None, variable_manager=None, loader=None):
    # only need play passed in when dynamic
    if play is None:
        myplay = self._parent._play
    else:
        myplay = play

    ri = RoleInclude.load(
        self._role_name, play=myplay, variable_manager=variable_manager, loader=loader
    )
    ri.vars.update(self.vars)

    # build role
    actual_role = Role.load(
        ri, myplay, parent_role=self._parent_role, from_files=self._from_files
    )
    actual_role._metadata.allow_duplicates = self.allow_duplicates

    # compile role with parent roles as dependencies to ensure they inherit
    # variables
    if not self._parent_role:
        dep_chain = []
    else:
        dep_chain = list(self._parent_role._parents)
        dep_chain.append(self._parent_role)

    blocks = actual_role.compile(play=myplay, dep_chain=dep_chain)
    for b in blocks:
        b._parent = self

    # updated available handlers in play
    handlers = actual_role.get_handler_blocks(play=myplay)
    myplay.handlers = myplay.handlers + handlers
    return blocks, handlers