Ensure handlers have proper parent (#39426)

* Ensure role handlers are parented correctly. Fixes #36518

* Add delegate_to test for include_role handlers
This commit is contained in:
Matt Martz 2018-04-27 12:03:57 -05:00 committed by GitHub
parent 85b42a6f68
commit 7db5ce2c86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 2 deletions

View file

@ -333,10 +333,10 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
# uses compiled list from object
blocks, _ = ir.get_block_list(variable_manager=variable_manager, loader=loader)
t = task_list.extend(blocks)
task_list.extend(blocks)
else:
# passes task object itself for latter generation of list
t = task_list.append(ir)
task_list.append(ir)
else:
if use_handlers:
t = Handler.load(task_ds, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)

View file

@ -96,6 +96,8 @@ class IncludeRole(TaskInclude):
# updated available handlers in play
handlers = actual_role.get_handler_blocks(play=myplay)
for h in handlers:
h._parent = self
myplay.handlers = myplay.handlers + handlers
return blocks, handlers

View file

@ -136,3 +136,8 @@
- name: Include role inside always
import_role:
name: role3
- name: Test delegate_to handler is delegated
import_role:
name: delegated_handler
delegate_to: localhost

View file

@ -0,0 +1,4 @@
- name: delegated assert handler
assert:
that:
- ansible_delegated_vars is defined

View file

@ -0,0 +1,3 @@
- command: "true"
notify:
- delegated assert handler