mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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:
parent
2c77cf1a49
commit
37d9acc097
4 changed files with 10 additions and 12 deletions
|
@ -112,7 +112,7 @@ class Play(object):
|
||||||
if plugin_name not in self.playbook.lookup_plugins_list:
|
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))
|
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)
|
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:
|
for item in items:
|
||||||
mv = task_vars.copy()
|
mv = task_vars.copy()
|
||||||
|
|
|
@ -170,12 +170,12 @@ class Runner(object):
|
||||||
for (k,v) in action_plugin_list.iteritems():
|
for (k,v) in action_plugin_list.iteritems():
|
||||||
self.action_plugins[k] = v.ActionModule(self)
|
self.action_plugins[k] = v.ActionModule(self)
|
||||||
for (k,v) in lookup_plugin_list.iteritems():
|
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():
|
for (k,v) in utils.import_plugins(os.path.join(self.basedir, 'action_plugins')).iteritems():
|
||||||
self.action_plugins[k] = v.ActionModule(self)
|
self.action_plugins[k] = v.ActionModule(self)
|
||||||
for (k,v) in utils.import_plugins(os.path.join(self.basedir, 'lookup_plugins')).iteritems():
|
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):
|
class LookupModule(object):
|
||||||
|
|
||||||
def __init__(self, runner):
|
def __init__(self, basedir=None, **kwargs):
|
||||||
self.runner = runner
|
self.basedir = basedir
|
||||||
|
|
||||||
def run(self, terms):
|
def run(self, terms, **kwargs):
|
||||||
return [ f for f in glob.glob(utils.path_dwim(self.runner.basedir, terms)) if os.path.isfile(f) ]
|
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
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
class LookupModule(object):
|
class LookupModule(object):
|
||||||
|
|
||||||
def __init__(self, runner):
|
def __init__(self, **kwargs):
|
||||||
self.runner = runner
|
pass
|
||||||
|
|
||||||
def run(self, terms):
|
def run(self, terms, **kwargs):
|
||||||
return terms
|
return terms
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue