From b8a66ce5bb050513e1cbd33f656f412d1fb1c88a Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sat, 1 Jun 2013 18:15:38 -0400 Subject: [PATCH] Lookup plugins in included files now look in paths relative to their files, allowing role usage. --- lib/ansible/runner/lookup_plugins/file.py | 1 + lib/ansible/utils/template.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/ansible/runner/lookup_plugins/file.py b/lib/ansible/runner/lookup_plugins/file.py index aed322ccb1..d5291c2267 100644 --- a/lib/ansible/runner/lookup_plugins/file.py +++ b/lib/ansible/runner/lookup_plugins/file.py @@ -25,6 +25,7 @@ class LookupModule(object): self.basedir = basedir def run(self, terms, inject=None, **kwargs): + terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject) ret = [] diff --git a/lib/ansible/utils/template.py b/lib/ansible/utils/template.py index 7553d89695..5d23e40258 100644 --- a/lib/ansible/utils/template.py +++ b/lib/ansible/utils/template.py @@ -81,6 +81,7 @@ def lookup(name, *args, **kwargs): from ansible import utils instance = utils.plugins.lookup_loader.get(name.lower(), basedir=kwargs.get('basedir',None)) vars = kwargs.get('vars', None) + if instance is not None: ran = instance.run(*args, inject=vars, **kwargs) return ",".join(ran) @@ -470,6 +471,12 @@ def template_from_string(basedir, data, vars): environment.filters.update(_get_filters()) environment.template_class = J2Template + if '_original_file' in vars: + basedir = os.path.dirname(vars['_original_file']) + filesdir = os.path.join(basedir, '..', 'files') + if os.path.exists(filesdir): + basedir = filesdir + # TODO: may need some way of using lookup plugins here seeing we aren't calling # the legacy engine, lookup() as a function, perhaps?