From da5de725d767a227f57a485627e34b3c7d687dcf Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 18 Sep 2014 15:53:41 -0500 Subject: [PATCH] Allow with_first_files to search relative to templates and vars in roles Fixes #8879 --- lib/ansible/runner/lookup_plugins/first_found.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/ansible/runner/lookup_plugins/first_found.py b/lib/ansible/runner/lookup_plugins/first_found.py index d394ee3a2fe..a48b56a3c28 100644 --- a/lib/ansible/runner/lookup_plugins/first_found.py +++ b/lib/ansible/runner/lookup_plugins/first_found.py @@ -172,14 +172,21 @@ class LookupModule(object): else: total_search = terms - result = None for fn in total_search: + if inject and '_original_file' in inject: + # check the templates and vars directories too, + # if they exist + for roledir in ('templates', 'vars'): + path = utils.path_dwim(os.path.join(self.basedir, '..', roledir), fn) + if os.path.exists(path): + return [path] + # if none of the above were found, just check the + # current filename against the basedir (this will already + # have ../files from runner, if it's a role task path = utils.path_dwim(self.basedir, fn) if os.path.exists(path): return [path] - - - if not result: + else: if skip: return [] else: