mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #3462 from stoned/filtererror
Introduce exception AnsibleFilterError and use it in Jinja filters. Ign...
This commit is contained in:
commit
0f4229f6c4
4 changed files with 43 additions and 34 deletions
|
@ -35,3 +35,6 @@ class AnsibleYAMLValidationFailed(AnsibleError):
|
||||||
|
|
||||||
class AnsibleUndefinedVariable(AnsibleError):
|
class AnsibleUndefinedVariable(AnsibleError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class AnsibleFilterError(AnsibleError):
|
||||||
|
pass
|
||||||
|
|
|
@ -326,7 +326,7 @@ class PlayBook(object):
|
||||||
ansible.callbacks.set_task(self.callbacks, task)
|
ansible.callbacks.set_task(self.callbacks, task)
|
||||||
ansible.callbacks.set_task(self.runner_callbacks, task)
|
ansible.callbacks.set_task(self.runner_callbacks, task)
|
||||||
|
|
||||||
self.callbacks.on_task_start(template(play.basedir, task.name, task.module_vars, lookup_fatal=False), is_handler)
|
self.callbacks.on_task_start(template(play.basedir, task.name, task.module_vars, lookup_fatal=False, filter_fatal=False), is_handler)
|
||||||
if hasattr(self.callbacks, 'skip_task') and self.callbacks.skip_task:
|
if hasattr(self.callbacks, 'skip_task') and self.callbacks.skip_task:
|
||||||
ansible.callbacks.set_task(self.callbacks, None)
|
ansible.callbacks.set_task(self.callbacks, None)
|
||||||
ansible.callbacks.set_task(self.runner_callbacks, None)
|
ansible.callbacks.set_task(self.runner_callbacks, None)
|
||||||
|
|
|
@ -34,7 +34,7 @@ def to_nice_json(*a, **kw):
|
||||||
def failed(*a, **kw):
|
def failed(*a, **kw):
|
||||||
item = a[0]
|
item = a[0]
|
||||||
if type(item) != dict:
|
if type(item) != dict:
|
||||||
raise errors.AnsibleError("|failed expects a dictionary")
|
raise errors.AnsibleFilterError("|failed expects a dictionary")
|
||||||
rc = item.get('rc',0)
|
rc = item.get('rc',0)
|
||||||
failed = item.get('failed',False)
|
failed = item.get('failed',False)
|
||||||
if rc != 0 or failed:
|
if rc != 0 or failed:
|
||||||
|
|
|
@ -295,9 +295,10 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis
|
||||||
|
|
||||||
# TODO: varname is misnamed here
|
# TODO: varname is misnamed here
|
||||||
|
|
||||||
def template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=True, convert_bare=False, fail_on_undefined=False):
|
def template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=True, convert_bare=False, fail_on_undefined=False, filter_fatal=True):
|
||||||
''' templates a data structure by traversing it and substituting for other data structures '''
|
''' templates a data structure by traversing it and substituting for other data structures '''
|
||||||
|
|
||||||
|
try:
|
||||||
if convert_bare and isinstance(varname, basestring):
|
if convert_bare and isinstance(varname, basestring):
|
||||||
first_part = varname.split(".")[0].split("[")[0]
|
first_part = varname.split(".")[0].split("[")[0]
|
||||||
if first_part in vars and '{{' not in varname and '$' not in varname:
|
if first_part in vars and '{{' not in varname and '$' not in varname:
|
||||||
|
@ -331,6 +332,11 @@ def template(basedir, varname, vars, lookup_fatal=True, depth=0, expand_lists=Tr
|
||||||
return d
|
return d
|
||||||
else:
|
else:
|
||||||
return varname
|
return varname
|
||||||
|
except errors.AnsibleFilterError:
|
||||||
|
if filter_fatal:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
return varname
|
||||||
|
|
||||||
|
|
||||||
class _jinja2_vars(object):
|
class _jinja2_vars(object):
|
||||||
|
|
Loading…
Reference in a new issue