diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 8bf8d6f7c1..a0d7688e1f 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -392,9 +392,16 @@ class Runner(object): if items_plugin is not None and items_plugin in utils.plugins.lookup_loader: + basedir = self.basedir + if '_original_file' in inject: + basedir = os.path.dirname(inject['_original_file']) + filesdir = os.path.join(basedir, '..', 'files') + if os.path.exists(filesdir): + basedir = filesdir + items_terms = self.module_vars.get('items_lookup_terms', '') - items_terms = template.template(self.basedir, items_terms, inject) - items = utils.plugins.lookup_loader.get(items_plugin, runner=self, basedir=self.basedir).run(items_terms, inject=inject) + items_terms = template.template(basedir, items_terms, inject) + items = utils.plugins.lookup_loader.get(items_plugin, runner=self, basedir=basedir).run(items_terms, inject=inject) if type(items) != list: raise errors.AnsibleError("lookup plugins have to return a list: %r" % items)