Handle getting the ds for Conditionals which may not be mixed in

pull/11414/head
James Cammarata 10 years ago
parent f433e709f2
commit 9d9cd0c42c

@ -55,14 +55,21 @@ class Conditional:
False if any of them evaluate as such. False if any of them evaluate as such.
''' '''
# since this is a mixin, it may not have an underlying datastructure
# associated with it, so we pull it out now in case we need it for
# error reporting below
ds = None
if hasattr(self, 'get_ds'):
ds = self.get_ds()
try: try:
for conditional in self.when: for conditional in self.when:
if not self._check_conditional(conditional, templar, all_vars): if not self._check_conditional(conditional, templar, all_vars):
return False return False
except UndefinedError, e: except UndefinedError, e:
raise AnsibleError("The conditional check '%s' failed due to an undefined variable. The error was: %s" % (conditional, e), obj=self.get_ds()) raise AnsibleError("The conditional check '%s' failed due to an undefined variable. The error was: %s" % (conditional, e), obj=ds)
except Exception, e: except Exception, e:
raise AnsibleError("The conditional check '%s' failed. The error was: %s" % (conditional, e), obj=self.get_ds()) raise AnsibleError("The conditional check '%s' failed. The error was: %s" % (conditional, e), obj=ds)
return True return True

Loading…
Cancel
Save