diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 88f69070eb..3faaee7e82 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -246,7 +246,8 @@ class TaskExecutor: task_vars[loop_var] = item try: - tmp_task = self._task.copy(exclude_tasks=True) + tmp_task = self._task.copy(exclude_parent=True, exclude_tasks=True) + tmp_task._parent = self._task._parent tmp_play_context = self._play_context.copy() except AnsibleParserError as e: results.append(dict(failed=True, msg=to_unicode(e))) diff --git a/test/units/executor/test_task_executor.py b/test/units/executor/test_task_executor.py index 12d1330239..60935692d5 100644 --- a/test/units/executor/test_task_executor.py +++ b/test/units/executor/test_task_executor.py @@ -139,7 +139,7 @@ class TestTaskExecutor(unittest.TestCase): mock_host = MagicMock() - def _copy(exclude_block=False, exclude_tasks=False): + def _copy(exclude_parent=False, exclude_tasks=False): new_item = MagicMock() return new_item