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

show specific undefined var errors on -v in debug (#32206)

* show specific undefined var errors on -v in debug

allows users to get more specific information about undefined errors
as they might be looking at a complex data structure and need to find
the specific leaf that has the issue

* now tests works at all verbosity levels

* updated to unicode objects
This commit is contained in:
Brian Coca 2017-11-02 18:11:31 -04:00 committed by GitHub
parent 9d28973b5e
commit e582a69e9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View file

@ -43,10 +43,8 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars)
verbosity = 0
# get task verbosity
if 'verbosity' in self._task.args:
verbosity = int(self._task.args['verbosity'])
verbosity = int(self._task.args.get('verbosity', 0))
if verbosity <= self._display.verbosity:
if 'msg' in self._task.args:
@ -61,8 +59,10 @@ class ActionModule(ActionBase):
raise AnsibleUndefinedVariable
# If var name is same as result, try to template it
results = self._templar.template("{{" + results + "}}", convert_bare=True, fail_on_undefined=True)
except AnsibleUndefinedVariable:
results = "VARIABLE IS NOT DEFINED!"
except AnsibleUndefinedVariable as e:
results = u"VARIABLE IS NOT DEFINED!"
if self._display.verbosity > 0:
results += u": %s" % to_text(e)
if isinstance(self._task.args['var'], (list, dict)):
# If var is a list or dict, use the type as key to display

View file

@ -44,7 +44,7 @@
- assert:
that:
- var_undefined.undefined_variable == 'VARIABLE IS NOT DEFINED!'
- "'VARIABLE IS NOT DEFINED!' in var_undefined.undefined_variable"
- same_value_as_var_name.same_value_as_var_name_var == 'same_value_as_var_name_var'
- name: cleanup temporary template output