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

Merge pull request #9646 from bcoca/listify_template_fixes

fine tuned lookup/templating errors
This commit is contained in:
Brian Coca 2014-11-26 22:20:33 -05:00
commit 60b51ef6c3
3 changed files with 10 additions and 6 deletions

View file

@ -50,7 +50,7 @@ class LookupModule(object):
if isinstance(term, basestring): if isinstance(term, basestring):
# convert a variable to a list # convert a variable to a list
term2 = utils.listify_lookup_plugin_terms(term, self.basedir, inject, fail_on_undefined=False) term2 = utils.listify_lookup_plugin_terms(term, self.basedir, inject)
# but avoid converting a plain string to a list of one string # but avoid converting a plain string to a list of one string
if term2 != [ term ]: if term2 != [ term ]:
term = term2 term = term2

View file

@ -1451,7 +1451,7 @@ def safe_eval(expr, locals={}, include_exceptions=False):
return expr return expr
def listify_lookup_plugin_terms(terms, basedir, inject, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR): def listify_lookup_plugin_terms(terms, basedir, inject):
from ansible.utils import template from ansible.utils import template
@ -1469,11 +1469,13 @@ def listify_lookup_plugin_terms(terms, basedir, inject, fail_on_undefined=C.DEFA
# if not already a list, get ready to evaluate with Jinja2 # if not already a list, get ready to evaluate with Jinja2
# not sure why the "/" is in above code :) # not sure why the "/" is in above code :)
try: try:
new_terms = template.template(basedir, "{{%s}}" % terms, inject, convert_bare=True, fail_on_undefined=fail_on_undefined) new_terms = template.template(basedir, terms, inject, convert_bare=True, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR)
if isinstance(new_terms, basestring) and "{{" in new_terms: if isinstance(new_terms, basestring) and "{{" in new_terms:
pass pass
else: else:
terms = new_terms terms = new_terms
except errors.AnsibleUndefinedVariable:
raise
except jinja2.exceptions.UndefinedError, e: except jinja2.exceptions.UndefinedError, e:
raise errors.AnsibleUndefinedVariable('undefined variable in items: %s' % e) raise errors.AnsibleUndefinedVariable('undefined variable in items: %s' % e)
except: except:

View file

@ -86,12 +86,14 @@ JINJA2_ALLOWED_OVERRIDES = ['trim_blocks', 'lstrip_blocks', 'newline_sequence',
def lookup(name, *args, **kwargs): def lookup(name, *args, **kwargs):
from ansible import utils from ansible import utils
instance = utils.plugins.lookup_loader.get(name.lower(), basedir=kwargs.get('basedir',None)) instance = utils.plugins.lookup_loader.get(name.lower(), basedir=kwargs.get('basedir',None))
vars = kwargs.get('vars', None) tvars = kwargs.get('vars', None)
if instance is not None: if instance is not None:
# safely catch run failures per #5059 # safely catch run failures per #5059
try: try:
ran = instance.run(*args, inject=vars, **kwargs) ran = instance.run(*args, inject=tvars, **kwargs)
except errors.AnsibleUndefinedVariable:
raise
except Exception, e: except Exception, e:
ran = None ran = None
if ran: if ran: