Skip to content

Commit

Permalink
Ensure handlers have proper parent (ansible#39426)
Browse files Browse the repository at this point in the history
* Ensure role handlers are parented correctly. Fixes ansible#36518

* Add delegate_to test for include_role handlers
  • Loading branch information
sivel authored and Alexander Bethke committed May 15, 2018
1 parent f434ab6 commit b5c3424
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ansible/playbook/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/ansible/playbook/role_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def get_block_list(self, play=None, variable_manager=None, loader=None):

# 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: delegated assert handler
assert:
that:
- ansible_delegated_vars is defined
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- command: "true"
notify:
- delegated assert handler

0 comments on commit b5c3424

Please sign in to comment.