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.
This commit is contained in:
Daniel Hokka Zakrisson 2012-10-31 16:52:31 +01:00
parent 2c77cf1a49
commit 37d9acc097
4 changed files with 10 additions and 12 deletions

View file

@ -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()

View file

@ -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)
# *****************************************************

View file

@ -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) ]

View file

@ -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