Merge pull request #9715 from bcoca/listify_revert_errorhandling

Listify revert errorhandling
pull/9933/head
Brian Coca 10 years ago committed by James Cammarata
parent ecdeed4342
commit b9f1503870

@ -733,6 +733,10 @@ class Runner(object):
result = utils.jsonify(dict(changed=False, skipped=True)) result = utils.jsonify(dict(changed=False, skipped=True))
self.callbacks.on_skipped(host, None) self.callbacks.on_skipped(host, None)
return ReturnData(host=host, result=result) return ReturnData(host=host, result=result)
except errors.AnsibleError, e:
raise
except Exception, e:
raise errors.AnsibleError("Unexpected error while executing task: %s" % str(e))
# strip out any jinja2 template syntax within # strip out any jinja2 template syntax within
# the data returned by the lookup plugin # the data returned by the lookup plugin

@ -48,7 +48,6 @@ import sys
import json import json
import subprocess import subprocess
import contextlib import contextlib
import jinja2.exceptions
from vault import VaultLib from vault import VaultLib
@ -1469,15 +1468,11 @@ def listify_lookup_plugin_terms(terms, basedir, inject):
# 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, terms, inject, convert_bare=True, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR) new_terms = template.template(basedir, "{{ %s }}" % terms, inject)
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:
raise errors.AnsibleUndefinedVariable('undefined variable in items: %s' % e)
except: except:
pass pass

@ -89,13 +89,12 @@ def lookup(name, *args, **kwargs):
tvars = 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
try: try:
ran = instance.run(*args, inject=tvars, **kwargs) ran = instance.run(*args, inject=tvars, **kwargs)
except errors.AnsibleUndefinedVariable: except errors.AnsibleError:
raise raise
except Exception, e: except Exception, e:
ran = None raise errors.AnsibleError('Unexpected error in during lookup: %s' % e)
if ran: if ran:
ran = ",".join(ran) ran = ",".join(ran)
return ran return ran

@ -566,17 +566,9 @@ class TestUtils(unittest.TestCase):
def test_listify_lookup_plugin_terms(self): def test_listify_lookup_plugin_terms(self):
basedir = os.path.dirname(__file__) basedir = os.path.dirname(__file__)
# Straight lookups # Straight lookups
self.assertEqual(ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=[])), []) #self.assertEqual(ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=[])), [])
self.assertEqual(ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=['one', 'two'])), ['one', 'two']) #self.assertEqual(ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=['one', 'two'])), ['one', 'two'])
# Variable interpolation
self.assertEqual(ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=['{{ foo }}', '{{ bar }}'], foo="hello", bar="world")),
['hello', 'world'])
with self.assertRaises(ansible.errors.AnsibleError) as ex:
ansible.utils.listify_lookup_plugin_terms('things', basedir, dict(things=['{{ foo }}', '{{ bar_typo }}'], foo="hello", bar="world"))
self.assertTrue("undefined variable in items: 'bar_typo'" in ex.exception.msg)
def test_deprecated(self): def test_deprecated(self):
sys_stderr = sys.stderr sys_stderr = sys.stderr

Loading…
Cancel
Save