Make sure all plugin loaders are loaded from roles and shared correctly (v2)

This commit is contained in:
James Cammarata
2015-05-01 23:48:11 -05:00
parent 0b836262f0
commit f310d13280
12 changed files with 80 additions and 45 deletions

View File

@@ -44,13 +44,13 @@ class ActionBase:
action in use.
'''
def __init__(self, task, connection, connection_info, loader, module_loader):
self._task = task
self._connection = connection
self._connection_info = connection_info
self._loader = loader
self._module_loader = module_loader
self._shell = self.get_shell()
def __init__(self, task, connection, connection_info, loader, shared_loader_obj):
self._task = task
self._connection = connection
self._connection_info = connection_info
self._loader = loader
self._shared_loader_obj = shared_loader_obj
self._shell = self.get_shell()
self._supports_check_mode = True
@@ -73,9 +73,9 @@ class ActionBase:
# Search module path(s) for named module.
module_suffixes = getattr(self._connection, 'default_suffixes', None)
module_path = self._module_loader.find_plugin(module_name, module_suffixes)
module_path = self._shared_loader_obj.module_loader.find_plugin(module_name, module_suffixes)
if module_path is None:
module_path2 = self._module_loader.find_plugin('ping', module_suffixes)
module_path2 = self._shared_loader_obj.module_loader.find_plugin('ping', module_suffixes)
if module_path2 is not None:
raise AnsibleError("The module %s was not found in configured module paths" % (module_name))
else:

View File

@@ -35,7 +35,7 @@ class ActionModule(ActionBase):
result = dict(msg=self._task.args['msg'])
# FIXME: move the LOOKUP_REGEX somewhere else
elif 'var' in self._task.args: # and not utils.LOOKUP_REGEX.search(self._task.args['var']):
templar = Templar(loader=self._loader, variables=task_vars)
templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=task_vars)
results = templar.template(self._task.args['var'], convert_bare=True)
result = dict()
result[self._task.args['var']] = results

View File

@@ -30,12 +30,24 @@ from ansible.inventory.group import Group
from ansible.playbook.handler import Handler
from ansible.playbook.helpers import load_list_of_blocks
from ansible.playbook.role import ROLE_CACHE, hash_params
from ansible.plugins import module_loader
from ansible.plugins import module_loader, filter_loader, lookup_loader
from ansible.utils.debug import debug
__all__ = ['StrategyBase']
# FIXME: this should probably be in the plugins/__init__.py, with
# a smarter mechanism to set all of the attributes based on
# the loaders created there
class SharedPluginLoaderObj:
'''
A simple object to make pass the various plugin loaders to
the forked processes over the queue easier
'''
def __init__(self):
self.module_loader = module_loader
self.filter_loader = filter_loader
self.lookup_loader = lookup_loader
class StrategyBase:
@@ -108,7 +120,12 @@ class StrategyBase:
self._cur_worker = 0
self._pending_results += 1
main_q.put((host, task, self._loader.get_basedir(), task_vars, connection_info, module_loader), block=False)
# create a dummy object with plugin loaders set as an easier
# way to share them with the forked processes
shared_loader_obj = SharedPluginLoaderObj()
main_q.put((host, task, self._loader.get_basedir(), task_vars, connection_info, shared_loader_obj), block=False)
except (EOFError, IOError, AssertionError) as e:
# most likely an abort
debug("got an error while queuing: %s" % e)