Reduce code duplication

This commit is contained in:
Daniel Hokka Zakrisson 2012-06-09 21:42:45 +02:00
parent c1b02d7805
commit 4e254f23d9

View file

@ -70,36 +70,29 @@ class Play(object):
def _load_tasks(self, ds, keyname): def _load_tasks(self, ds, keyname):
''' handle task and handler include statements ''' ''' handle task and handler include statements '''
items = ds.get(keyname, []) tasks = ds.get(keyname, [])
results = [] results = []
for x in items: for x in tasks:
if 'include' in x:
task_vars = self.vars.copy() task_vars = self.vars.copy()
if 'include' in x:
tokens = shlex.split(x['include']) tokens = shlex.split(x['include'])
for t in tokens[1:]: for t in tokens[1:]:
(k,v) = t.split("=", 1) (k,v) = t.split("=", 1)
task_vars[k]=v task_vars[k]=v
include_file = tokens[0] include_file = tokens[0]
data = utils.parse_yaml_from_file(utils.path_dwim(self.playbook.basedir, include_file)) data = utils.parse_yaml_from_file(utils.path_dwim(self.playbook.basedir, include_file))
elif type(x) == dict:
data = [x]
else:
raise Exception("unexpected task type")
for y in data: for y in data:
items = y.get('with_items',None) items = y.get('with_items',None)
if items is None: if items is None:
items = [ '' ] items = [ '' ]
for item in items: for item in items:
mv = self.vars.copy() mv = task_vars.copy()
mv.update(task_vars)
mv['item'] = item mv['item'] = item
results.append(Task(self,y,module_vars=mv)) results.append(Task(self,y,module_vars=mv))
elif type(x) == dict:
items = x.get('with_items', None)
if items is None:
items = [ '' ]
for item in items:
mv = self.vars.copy()
mv['item'] = item
results.append(Task(self,x,module_vars=mv))
else:
raise Exception("unexpected task type")
return results return results
# ************************************************* # *************************************************