From 9bdde13126f086c0dda1006b3360447e49509348 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 17 Oct 2016 10:32:28 -0400 Subject: [PATCH] fixes to ansible_search_path now gets basedir (no need to frontload as dwim already does that) added comment about basedir to search_path usage to avoid dupes --- lib/ansible/executor/task_executor.py | 12 +++++++++--- lib/ansible/plugins/action/__init__.py | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index bfd698038c5..7adafa0a9ab 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -85,9 +85,6 @@ class TaskExecutor: display.debug("in run()") try: - # get search path for this task to pass to lookup plugins - self._job_vars['ansible_search_path'] = self._task.get_search_path() - items = self._get_loop_items() if items is not None: if len(items) > 0: @@ -173,6 +170,10 @@ class TaskExecutor: old_vars[k] = self._job_vars[k] self._job_vars[k] = play_context_vars[k] + # get search path for this task to pass to lookup plugins + self._job_vars['ansible_search_path'] = self._task.get_search_path() + + templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=self._job_vars) items = None if self._task.loop: @@ -212,6 +213,11 @@ class TaskExecutor: for idx, item in enumerate(items): 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/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 1919ab492a7..c58a7a205e3 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -817,6 +817,7 @@ class ActionBase(with_metaclass(ABCMeta, object)): to get back the first existing file found. ''' + # dwim already deals with playbook basedirs path_stack = self._task.get_search_path() result = self._loader.path_dwim_relative_stack(path_stack, dirname, needle)