Make lookup API extensible and allow basedir to be passed

This allows using with_fileglob in play context, e.g.
- include: $item
  with_fileglob: tasks/*.yml
as well as prepares for other data to be passed.
pull/1648/head
Daniel Hokka Zakrisson 12 years ago
parent 2c77cf1a49
commit 37d9acc097

@ -112,7 +112,7 @@ class Play(object):
if plugin_name not in self.playbook.lookup_plugins_list:
raise errors.AnsibleError("cannot find lookup plugin named %s for usage in with_%s" % (plugin_name, plugin_name))
terms = utils.varReplaceWithItems(self.basedir, x[k], task_vars)
items = self.playbook.lookup_plugins_list[plugin_name].LookupModule(None).run(terms)
items = self.playbook.lookup_plugins_list[plugin_name].LookupModule(basedir=self.basedir, runner=None).run(terms)
for item in items:
mv = task_vars.copy()

@ -170,12 +170,12 @@ class Runner(object):
for (k,v) in action_plugin_list.iteritems():
self.action_plugins[k] = v.ActionModule(self)
for (k,v) in lookup_plugin_list.iteritems():
self.lookup_plugins[k] = v.LookupModule(self)
self.lookup_plugins[k] = v.LookupModule(runner=self, basedir=self.basedir)
for (k,v) in utils.import_plugins(os.path.join(self.basedir, 'action_plugins')).iteritems():
self.action_plugins[k] = v.ActionModule(self)
for (k,v) in utils.import_plugins(os.path.join(self.basedir, 'lookup_plugins')).iteritems():
self.lookup_plugins[k] = v.LookupModule(self)
self.lookup_plugins[k] = v.LookupModule(runner=self, basedir=self.basedir)
# *****************************************************

@ -21,11 +21,11 @@ from ansible import utils
class LookupModule(object):
def __init__(self, runner):
self.runner = runner
def __init__(self, basedir=None, **kwargs):
self.basedir = basedir
def run(self, terms):
return [ f for f in glob.glob(utils.path_dwim(self.runner.basedir, terms)) if os.path.isfile(f) ]
def run(self, terms, **kwargs):
return [ f for f in glob.glob(utils.path_dwim(self.basedir, terms)) if os.path.isfile(f) ]

@ -15,14 +15,12 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import os
class LookupModule(object):
def __init__(self, runner):
self.runner = runner
def __init__(self, **kwargs):
pass
def run(self, terms):
def run(self, terms, **kwargs):
return terms

Loading…
Cancel
Save