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

fixed listify for lookups, made sure convert_bare is only on with_

This commit is contained in:
Brian Coca 2015-08-11 16:38:42 -04:00
parent adb9d7e461
commit 6e825e8c22
3 changed files with 6 additions and 8 deletions

View file

@ -153,7 +153,8 @@ class TaskExecutor:
items = None items = None
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:
loop_terms = listify_lookup_plugin_terms(terms=self._task.loop_args, templar=templar, loader=self._loader, fail_on_undefined=True) #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)
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)

View file

@ -251,11 +251,10 @@ class Templar:
instance = self._lookup_loader.get(name.lower(), loader=self._loader, templar=self) instance = self._lookup_loader.get(name.lower(), loader=self._loader, templar=self)
if instance is not None: if instance is not None:
from ansible.utils.listify import listify_lookup_plugin_terms loop_terms = listify_lookup_plugin_terms(terms=args, templar=self, loader=self._loader, fail_on_undefined=True, convert_bare=False)
loop_terms = listify_lookup_plugin_terms(terms=args, templar=self, loader=self._loader, fail_on_undefined=True)
# safely catch run failures per #5059 # safely catch run failures per #5059
try: try:
ran = instance.run(*args, variables=self._available_variables, **kwargs) ran = instance.run(*loop_terms, variables=self._available_variables, **kwargs)
except (AnsibleUndefinedVariable, UndefinedError): except (AnsibleUndefinedVariable, UndefinedError):
raise raise
except Exception, e: except Exception, e:

View file

@ -26,14 +26,12 @@ from ansible.template.safe_eval import safe_eval
__all__ = ['listify_lookup_plugin_terms'] __all__ = ['listify_lookup_plugin_terms']
#FIXME: probably just move this into lookup plugin base class #FIXME: probably just move this into lookup plugin base class
def listify_lookup_plugin_terms(terms, templar, loader, fail_on_undefined=False): def listify_lookup_plugin_terms(terms, templar, loader, fail_on_undefined=False, convert_bare=False):
if isinstance(terms, basestring): if isinstance(terms, basestring):
stripped = terms.strip() stripped = terms.strip()
#FIXME: warn/deprecation on bare vars in with_ so we can eventually remove fail on undefined override #FIXME: warn/deprecation on bare vars in with_ so we can eventually remove fail on undefined override
terms = templar.template(terms, convert_bare=True, fail_on_undefined=fail_on_undefined) terms = templar.template(terms, convert_bare=convert_bare, fail_on_undefined=fail_on_undefined)
#TODO: check if this is needed as template should also return correct type already
#terms = safe_eval(terms)
else: else:
terms = templar.template(terms, fail_on_undefined=fail_on_undefined) terms = templar.template(terms, fail_on_undefined=fail_on_undefined)