From 028f216689022a2e81e066b2a570055b03f52b81 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sat, 14 Jul 2012 13:23:14 -0400 Subject: [PATCH] Error handling and magic around with_items, to let you know when variables are usable inside it and when not. --- lib/ansible/playbook/play.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 8f46b0dbbe..44b9320b60 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -63,6 +63,9 @@ class Play(object): self.sudo_user = ds.get('sudo_user', self.playbook.sudo_user) self.transport = ds.get('connection', self.playbook.transport) self.tags = ds.get('tags', None) + + self._update_vars_files_for_host(None) + self._tasks = self._load_tasks(self._ds, 'tasks') self._handlers = self._load_tasks(self._ds, 'handlers') @@ -75,6 +78,7 @@ class Play(object): if self.sudo_user != 'root': self.sudo = True + # ************************************************* @@ -104,6 +108,10 @@ class Play(object): elif isinstance(items, basestring): items = utils.varLookup(items, task_vars) for item in items: + item = utils.template(item, task_vars) + if self._has_vars_in(item): + raise errors.AnsibleError("parse error: unbound variable in with_items: %s" % item) + mv = task_vars.copy() mv['item'] = item results.append(Task(self,y,module_vars=mv)) @@ -161,10 +169,6 @@ class Play(object): def update_vars_files(self, hosts): ''' calculate vars_files, which requires that setup runs first so ansible facts can be mixed in ''' - # first process things that are not really host specific - # and we can just keep one reference to them - self._update_vars_files_for_host(None) - # now loop through all the hosts... for h in hosts: self._update_vars_files_for_host(h)