Reduce code duplication
This commit is contained in:
parent
c1b02d7805
commit
4e254f23d9
1 changed files with 10 additions and 17 deletions
|
@ -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
|
||||||
|
|
||||||
# *************************************************
|
# *************************************************
|
||||||
|
|
Loading…
Reference in a new issue