Commit ee2e31b3 by Brian Coca

now passes the test of skipping list when dict attribute is undefined, added…

now passes the test of skipping list when dict attribute is undefined, added deprecation warning as this seems like bad behaviour
parent 87926cbb
...@@ -26,7 +26,7 @@ import sys ...@@ -26,7 +26,7 @@ import sys
import time import time
from ansible import constants as C from ansible import constants as C
from ansible.errors import AnsibleError, AnsibleParserError from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVariable
from ansible.playbook.conditional import Conditional from ansible.playbook.conditional import Conditional
from ansible.playbook.task import Task from ansible.playbook.task import Task
from ansible.plugins import connection_loader, action_loader from ansible.plugins import connection_loader, action_loader
...@@ -154,7 +154,14 @@ class TaskExecutor: ...@@ -154,7 +154,14 @@ class TaskExecutor:
if self._task.loop: if self._task.loop:
if self._task.loop in self._shared_loader_obj.lookup_loader: if self._task.loop in self._shared_loader_obj.lookup_loader:
#TODO: remove convert_bare true and deprecate this in with_ #TODO: remove convert_bare true and deprecate this in with_
loop_terms = listify_lookup_plugin_terms(terms=self._task.loop_args, templar=templar, loader=self._loader, fail_on_undefined=True, convert_bare=True) try:
loop_terms = listify_lookup_plugin_terms(terms=self._task.loop_args, templar=templar, loader=self._loader, fail_on_undefined=True, convert_bare=True)
except AnsibleUndefinedVariable as e:
if 'has no attribute' in str(e):
loop_terms = []
self._display.deprecated("Skipping task due to undefined attribute, in the future this will be a fatal error.")
else:
raise
items = self._shared_loader_obj.lookup_loader.get(self._task.loop, loader=self._loader, templar=templar).run(terms=loop_terms, variables=vars_copy) items = self._shared_loader_obj.lookup_loader.get(self._task.loop, loader=self._loader, templar=templar).run(terms=loop_terms, variables=vars_copy)
else: else:
raise AnsibleError("Unexpected failure in finding the lookup named '%s' in the available lookup plugins" % self._task.loop) raise AnsibleError("Unexpected failure in finding the lookup named '%s' in the available lookup plugins" % self._task.loop)
......
...@@ -256,8 +256,8 @@ class Templar: ...@@ -256,8 +256,8 @@ class Templar:
# safely catch run failures per #5059 # safely catch run failures per #5059
try: try:
ran = instance.run(loop_terms, variables=self._available_variables, **kwargs) ran = instance.run(loop_terms, variables=self._available_variables, **kwargs)
except (AnsibleUndefinedVariable, UndefinedError): except (AnsibleUndefinedVariable, UndefinedError) as e:
raise raise AnsibleUndefinedVariable(e)
except Exception, e: except Exception, e:
if self._fail_on_lookup_errors: if self._fail_on_lookup_errors:
raise raise
...@@ -337,7 +337,7 @@ class Templar: ...@@ -337,7 +337,7 @@ class Templar:
return res return res
except (UndefinedError, AnsibleUndefinedVariable), e: except (UndefinedError, AnsibleUndefinedVariable), e:
if fail_on_undefined: if fail_on_undefined:
raise raise AnsibleUndefinedVariable(e)
else: else:
#TODO: return warning about undefined var #TODO: return warning about undefined var
return data return data
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment