Fixing v2 code for test_yum and added capability to squash items

This commit is contained in:
James Cammarata 2015-01-20 01:16:19 -06:00
parent 5addbe7956
commit eae9a406ad
4 changed files with 25 additions and 10 deletions

View file

@ -33,7 +33,6 @@ try:
except ImportError:
HAS_ATFORK=False
from ansible.executor.task_result import TaskResult
from ansible.playbook.handler import Handler
from ansible.playbook.task import Task
@ -130,7 +129,7 @@ class ResultProcess(multiprocessing.Process):
for notify in result._task.notify:
self._send_result(('notify_handler', result._host, notify))
if 'results' in result._result:
if result._task.loop:
# this task had a loop, and has more than one result, so
# loop over all of them instead of a single result
result_items = result._result['results']

View file

@ -112,14 +112,12 @@ class TaskExecutor:
results = []
# FIXME: squash items into a flat list here for those modules
# which support it (yum, apt, etc.) but make it smarter
# than it is today?
for item in items:
# make copies of the job vars and task so we can add the item to
# the variables and re-validate the task with the item variable
task_vars = self._job_vars.copy()
items = self._squash_items(items, task_vars)
for item in items:
task_vars['item'] = item
try:
@ -143,6 +141,22 @@ class TaskExecutor:
return results
def _squash_items(self, items, variables):
'''
Squash items down to a comma-separated list for certain modules which support it
(typically package management modules).
'''
if len(items) > 0 and self._task.action in ('apt', 'yum', 'pkgng', 'zypper'):
final_items = []
for item in items:
variables['item'] = item
if self._task.evaluate_conditional(variables):
final_items.append(item)
return [",".join(final_items)]
else:
return items
def _execute(self, variables=None):
'''
The primary workhorse of the executor system, this runs the task

View file

@ -55,6 +55,7 @@ class TaskResult:
if 'results' in self._result:
flag = False
for res in self._result.get('results', []):
if isinstance(res, dict):
flag |= res.get(key, False)
else:
return self._result.get(key, False)

View file

@ -17,7 +17,8 @@ from ansible.utils.vars import combine_vars
from ansible.vars import VariableManager
# Implement an ansible.utils.warning() function later
warning = print
import __builtin__
warning = getattr(__builtin__, 'print')
#---------------------------------------------------------------------------------------------------