1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Properly catch and report conditional test failures

This commit is contained in:
James Cammarata 2015-06-27 15:37:10 -04:00
parent 0eb1c880dd
commit 8ef28253e3

View file

@ -19,6 +19,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from jinja2.exceptions import UndefinedError
from ansible.errors import *
from ansible.playbook.attribute import FieldAttribute
from ansible.template import Templar
@ -53,9 +55,14 @@ class Conditional:
False if any of them evaluate as such.
'''
for conditional in self.when:
if not self._check_conditional(conditional, templar, all_vars):
return False
try:
for conditional in self.when:
if not self._check_conditional(conditional, templar, all_vars):
return False
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())
except Exception, e:
raise AnsibleError("The conditional check '%s' failed. The error was: %s" % (conditional, e), obj=self.get_ds())
return True