From a7f45c0660ca08cf6bb34ad9063a5271594012dc Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 31 Jul 2018 10:51:32 -0500 Subject: [PATCH] Add basedir to ansible_search_path before running loops. Fixes #43302 (#43431) --- lib/ansible/executor/task_executor.py | 8 ++++---- test/integration/targets/loops/tasks/main.yml | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index f09bc63dd0f..53bddc555f5 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -202,6 +202,10 @@ class TaskExecutor: # get search path for this task to pass to lookup plugins self._job_vars['ansible_search_path'] = self._task.get_search_path() + # ensure basedir is always in (dwim already searches here but we need to display it) + if self._loader.get_basedir() not in self._job_vars['ansible_search_path']: + self._job_vars['ansible_search_path'].append(self._loader.get_basedir()) + templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=self._job_vars) items = None if self._task.loop_with: @@ -253,10 +257,6 @@ class TaskExecutor: if item is not None and not isinstance(item, UnsafeProxy): items[idx] = UnsafeProxy(item) - # ensure basedir is always in (dwim already searches here but we need to display it) - if self._loader.get_basedir() not in self._job_vars['ansible_search_path']: - self._job_vars['ansible_search_path'].append(self._loader.get_basedir()) - return items def _run_loop(self, items): diff --git a/test/integration/targets/loops/tasks/main.yml b/test/integration/targets/loops/tasks/main.yml index 2c83d2f0fa9..8b1d635e6e5 100644 --- a/test/integration/targets/loops/tasks/main.yml +++ b/test/integration/targets/loops/tasks/main.yml @@ -223,3 +223,13 @@ - assert: that: - with_list_passed_a_dict is failed + +- debug: + var: "item" + loop: + - "{{ ansible_search_path }}" + register: loop_search_path + +- assert: + that: + - ansible_search_path == loop_search_path.results.0.item