fixes issue 11286 where role handlers are not run

This commit is contained in:
Benno Joy 2015-06-20 14:10:41 +05:30 committed by James Cammarata
parent 6e61881e80
commit be81b650e8
4 changed files with 21 additions and 1 deletions

View file

@ -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()

View file

@ -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:

View file

@ -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

View file

@ -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')