diff --git a/lib/ansible/executor/play_iterator.py b/lib/ansible/executor/play_iterator.py index d7c9661489..585c6556eb 100644 --- a/lib/ansible/executor/play_iterator.py +++ b/lib/ansible/executor/play_iterator.py @@ -100,6 +100,9 @@ class PlayIterator: for host in inventory.get_hosts(self._play.hosts): self._host_states[host.name] = HostState(blocks=self._blocks) + # Extend the play handlers list to include the handlers defined in roles + self._play.handlers.extend(play.compile_roles_handlers()) + def get_host_state(self, host): try: return self._host_states[host.name].copy() diff --git a/lib/ansible/executor/process/result.py b/lib/ansible/executor/process/result.py index 352b532cd4..1b8f4f5d31 100644 --- a/lib/ansible/executor/process/result.py +++ b/lib/ansible/executor/process/result.py @@ -129,6 +129,9 @@ class ResultProcess(multiprocessing.Process): # So, per the docs, we reassign the list so the proxy picks up and # notifies all other threads for notify in result._task.notify: + if result._task._role: + role_name = result._task._role.get_name() + notify = "%s : %s" %(role_name, notify) self._send_result(('notify_handler', result._host, notify)) if result._task.loop: diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 49a986555c..ffa526d0ff 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -206,6 +206,20 @@ class Play(Base, Taggable, Become): return block_list + def compile_roles_handlers(self): + ''' + Handles the role handler compilation step, returning a flat list of Handlers + This is done for all roles in the Play. + ''' + + block_list = [] + + if len(self.roles) > 0: + for r in self.roles: + block_list.extend(r.get_handler_blocks()) + + return block_list + def compile(self): ''' Compiles and returns the task list for this play, compiled from the diff --git a/lib/ansible/playbook/role/__init__.py b/lib/ansible/playbook/role/__init__.py index bea61147ae..b453d93740 100644 --- a/lib/ansible/playbook/role/__init__.py +++ b/lib/ansible/playbook/role/__init__.py @@ -172,7 +172,7 @@ class Role(Base, Become, Conditional, Taggable): handler_data = self._load_role_yaml('handlers') if handler_data: - self._handler_blocks = load_list_of_blocks(handler_data, play=None, role=self, loader=self._loader) + self._handler_blocks = load_list_of_blocks(handler_data, play=None, role=self, use_handlers=True, loader=self._loader) # vars and default vars are regular dictionaries self._role_vars = self._load_role_yaml('vars')