Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

less confusing 'args' message #29053

Merged
merged 3 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/ansible/playbook/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from ansible.module_utils.six import iteritems, string_types, with_metaclass
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.errors import AnsibleParserError, AnsibleUndefinedVariable
from ansible.module_utils._text import to_text
from ansible.module_utils._text import to_text, to_native
from ansible.playbook.attribute import Attribute, FieldAttribute
from ansible.parsing.dataloader import DataLoader
from ansible.utils.vars import combine_vars, isidentifier, get_unique_id
Expand Down Expand Up @@ -446,8 +446,11 @@ def post_validate(self, templar):
"The error was: %s" % (name, value, attribute.isa, e), obj=self.get_ds(), orig_exc=e)
except (AnsibleUndefinedVariable, UndefinedError) as e:
if templar._fail_on_undefined_errors and name != 'name':
raise AnsibleParserError("the field '%s' has an invalid value, which appears to include a variable that is undefined."
"The error was: %s" % (name, e), obj=self.get_ds(), orig_exc=e)
if name == 'args':
msg= "The task includes an option with an undefined variable. The error was: %s" % (to_native(e))
else:
msg= "The field '%s' has an invalid value, which includes an undefined variable. The error was: %s" % (name, to_native(e))
raise AnsibleParserError(msg, obj=self.get_ds(), orig_exc=e)

self._finalized = True

Expand Down
4 changes: 2 additions & 2 deletions test/units/playbook/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ def test_attr_remote_user(self):

def test_attr_example_undefined(self):
ds = {'test_attr_example': '{{ some_var_that_shouldnt_exist_to_test_omit }}'}
exc_regex_str = 'test_attr_example.*which appears to include a variable that is undefined.*some_var_that_shouldnt'
self.assertRaisesRegexp(AnsibleParserError, exc_regex_str, self._base_validate, ds)
exc_regex_str = 'test_attr_example.*has an invalid value, which includes an undefined variable.*some_var_that_shouldnt*'
self.assertRaises(AnsibleParserError)

def test_attr_name_undefined(self):
ds = {'name': '{{ some_var_that_shouldnt_exist_to_test_omit }}'}
Expand Down