From 4e254f23d9d31887dd15e49319e82e4e14f16ed3 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Sat, 9 Jun 2012 21:42:45 +0200 Subject: [PATCH] Reduce code duplication --- lib/ansible/playbook/play.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index cd7a4618677..3f579747f40 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -70,36 +70,29 @@ class Play(object): def _load_tasks(self, ds, keyname): ''' handle task and handler include statements ''' - items = ds.get(keyname, []) + tasks = ds.get(keyname, []) results = [] - for x in items: + for x in tasks: + task_vars = self.vars.copy() if 'include' in x: - task_vars = self.vars.copy() tokens = shlex.split(x['include']) for t in tokens[1:]: (k,v) = t.split("=", 1) task_vars[k]=v include_file = tokens[0] data = utils.parse_yaml_from_file(utils.path_dwim(self.playbook.basedir, include_file)) - for y in data: - items = y.get('with_items',None) - if items is None: - items = [ '' ] - for item in items: - mv = self.vars.copy() - mv.update(task_vars) - mv['item'] = item - results.append(Task(self,y,module_vars=mv)) elif type(x) == dict: - items = x.get('with_items', None) + data = [x] + else: + raise Exception("unexpected task type") + for y in data: + items = y.get('with_items',None) if items is None: items = [ '' ] for item in items: - mv = self.vars.copy() + mv = task_vars.copy() mv['item'] = item - results.append(Task(self,x,module_vars=mv)) - else: - raise Exception("unexpected task type") + results.append(Task(self,y,module_vars=mv)) return results # *************************************************