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

@@ -248,12 +248,11 @@ class ConnectionInformation:
def _get_fields(self):
return [i for i in self.__dict__.keys() if i[:1] != '_']
def post_validate(self, variables, loader):
def post_validate(self, templar):
'''
Finalizes templated values which may be set on this objects fields.
'''
templar = Templar(loader=loader, variables=variables)
for field in self._get_fields():
value = templar.template(getattr(self, field))
setattr(self, field, value)

View File

@@ -25,6 +25,7 @@ from ansible import constants as C
from ansible.errors import *
from ansible.executor.task_queue_manager import TaskQueueManager
from ansible.playbook import Playbook
from ansible.template import Templar
from ansible.utils.color import colorize, hostcolor
from ansible.utils.debug import debug
@@ -80,8 +81,9 @@ class PlaybookExecutor:
# Create a temporary copy of the play here, so we can run post_validate
# on it without the templating changes affecting the original object.
all_vars = self._variable_manager.get_vars(loader=self._loader, play=play)
templar = Templar(loader=self._loader, variables=all_vars, fail_on_undefined=False)
new_play = play.copy()
new_play.post_validate(all_vars, fail_on_undefined=False)
new_play.post_validate(templar)
if self._tqm is None:
# we are just doing a listing

View File

@@ -94,7 +94,7 @@ class WorkerProcess(multiprocessing.Process):
try:
if not self._main_q.empty():
debug("there's work to be done!")
(host, task, basedir, job_vars, connection_info, module_loader) = self._main_q.get(block=False)
(host, task, basedir, job_vars, connection_info, shared_loader_obj) = self._main_q.get(block=False)
debug("got a task/handler to work on: %s" % task)
# because the task queue manager starts workers (forks) before the
@@ -115,7 +115,7 @@ class WorkerProcess(multiprocessing.Process):
# execute the task and build a TaskResult from the result
debug("running TaskExecutor() for %s/%s" % (host, task))
executor_result = TaskExecutor(host, task, job_vars, new_connection_info, self._new_stdin, self._loader, module_loader).run()
executor_result = TaskExecutor(host, task, job_vars, new_connection_info, self._new_stdin, self._loader, shared_loader_obj).run()
debug("done running TaskExecutor() for %s/%s" % (host, task))
task_result = TaskResult(host, task, executor_result)

View File

@@ -31,6 +31,7 @@ from ansible.executor.connection_info import ConnectionInformation
from ansible.playbook.conditional import Conditional
from ansible.playbook.task import Task
from ansible.plugins import lookup_loader, connection_loader, action_loader
from ansible.template import Templar
from ansible.utils.listify import listify_lookup_plugin_terms
from ansible.utils.unicode import to_unicode
@@ -47,14 +48,14 @@ class TaskExecutor:
class.
'''
def __init__(self, host, task, job_vars, connection_info, new_stdin, loader, module_loader):
self._host = host
self._task = task
self._job_vars = job_vars
self._connection_info = connection_info
self._new_stdin = new_stdin
self._loader = loader
self._module_loader = module_loader
def __init__(self, host, task, job_vars, connection_info, new_stdin, loader, shared_loader_obj):
self._host = host
self._task = task
self._job_vars = job_vars
self._connection_info = connection_info
self._new_stdin = new_stdin
self._loader = loader
self._shared_loader_obj = shared_loader_obj
def run(self):
'''
@@ -195,9 +196,11 @@ class TaskExecutor:
if variables is None:
variables = self._job_vars
templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=variables)
# fields set from the play/task may be based on variables, so we have to
# do the same kind of post validation step on it here before we use it.
self._connection_info.post_validate(variables=variables, loader=self._loader)
self._connection_info.post_validate(templar=templar)
# now that the connection information is finalized, we can add 'magic'
# variables to the variable dictionary
@@ -216,7 +219,7 @@ class TaskExecutor:
return dict(changed=False, skipped=True, skip_reason='Conditional check failed')
# Now we do final validation on the task, which sets all fields to their final values
self._task.post_validate(variables)
self._task.post_validate(templar=templar)
# if this task is a TaskInclude, we just return now with a success code so the
# main thread can expand the task list for the given host
@@ -336,7 +339,7 @@ class TaskExecutor:
connection=self._connection,
connection_info=self._connection_info,
loader=self._loader,
module_loader=self._module_loader,
shared_loader_obj=self._shared_loader_obj,
)
time_left = self._task.async
@@ -408,7 +411,7 @@ class TaskExecutor:
connection=connection,
connection_info=self._connection_info,
loader=self._loader,
module_loader=self._module_loader,
shared_loader_obj=self._shared_loader_obj,
)
if not handler:

View File

@@ -32,6 +32,7 @@ from ansible.executor.process.worker import WorkerProcess
from ansible.executor.process.result import ResultProcess
from ansible.executor.stats import AggregateStats
from ansible.plugins import callback_loader, strategy_loader
from ansible.template import Templar
from ansible.utils.debug import debug
@@ -159,9 +160,10 @@ class TaskQueueManager:
'''
all_vars = self._variable_manager.get_vars(loader=self._loader, play=play)
templar = Templar(loader=self._loader, variables=all_vars, fail_on_undefined=False)
new_play = play.copy()
new_play.post_validate(all_vars, fail_on_undefined=False)
new_play.post_validate(templar)
connection_info = ConnectionInformation(new_play, self._options, self.passwords)
for callback_plugin in self._callback_plugins: