From 7db5ce2c86da3d1fc2f4c90294ff258267d8aae5 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Fri, 27 Apr 2018 12:03:57 -0500 Subject: [PATCH] Ensure handlers have proper parent (#39426) * Ensure role handlers are parented correctly. Fixes #36518 * Add delegate_to test for include_role handlers --- lib/ansible/playbook/helpers.py | 4 ++-- lib/ansible/playbook/role_include.py | 2 ++ .../targets/include_import/role/test_import_role.yml | 5 +++++ .../include_import/roles/delegated_handler/handlers/main.yml | 4 ++++ .../include_import/roles/delegated_handler/tasks/main.yml | 3 +++ 5 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/integration/targets/include_import/roles/delegated_handler/handlers/main.yml create mode 100644 test/integration/targets/include_import/roles/delegated_handler/tasks/main.yml diff --git a/lib/ansible/playbook/helpers.py b/lib/ansible/playbook/helpers.py index 86c0c14f84..58a58fca5b 100644 --- a/lib/ansible/playbook/helpers.py +++ b/lib/ansible/playbook/helpers.py @@ -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) diff --git a/lib/ansible/playbook/role_include.py b/lib/ansible/playbook/role_include.py index f2d50c49d3..2b95deb650 100644 --- a/lib/ansible/playbook/role_include.py +++ b/lib/ansible/playbook/role_include.py @@ -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 diff --git a/test/integration/targets/include_import/role/test_import_role.yml b/test/integration/targets/include_import/role/test_import_role.yml index 8a8bdc1724..492e32a567 100644 --- a/test/integration/targets/include_import/role/test_import_role.yml +++ b/test/integration/targets/include_import/role/test_import_role.yml @@ -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 diff --git a/test/integration/targets/include_import/roles/delegated_handler/handlers/main.yml b/test/integration/targets/include_import/roles/delegated_handler/handlers/main.yml new file mode 100644 index 0000000000..550ddc21ec --- /dev/null +++ b/test/integration/targets/include_import/roles/delegated_handler/handlers/main.yml @@ -0,0 +1,4 @@ +- name: delegated assert handler + assert: + that: + - ansible_delegated_vars is defined diff --git a/test/integration/targets/include_import/roles/delegated_handler/tasks/main.yml b/test/integration/targets/include_import/roles/delegated_handler/tasks/main.yml new file mode 100644 index 0000000000..9d2ef61c3b --- /dev/null +++ b/test/integration/targets/include_import/roles/delegated_handler/tasks/main.yml @@ -0,0 +1,3 @@ +- command: "true" + notify: + - delegated assert handler