summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2017-09-06 18:20:06 -0400
committerBrian Coca <brian.coca+git@gmail.com>2017-09-06 19:50:07 -0400
commit7787ed26bf0798b1144d7a92a4e2aa6fcbb18343 (patch)
treebd0d780d640e1fcbd7d8f3dbb6a046f1c8d20cd0
parent64db935b25bbaad0fe290e3ef39f34e5a3ac5a9c (diff)
downloadansible-7787ed26bf0798b1144d7a92a4e2aa6fcbb18343.tar.gz
less confusing 'args' message (#29053)
* less confusing 'args' message * fix test (cherry picked from commit fe3b4325c203c2665ff7da68c5150da12326cc14)
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/ansible/playbook/base.py9
-rw-r--r--test/units/playbook/test_base.py4
3 files changed, 9 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 46aadd3d79..e313c593ce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,7 @@ Ansible Changes By Release
* allow 'bridge' facts to work for certain containers that create conflicting ones with connection plugins
* Fix for win_get_url to use TLS 1.2/1.1 if it is available on the host
* Fix for the filetree lookup with non-ascii group names
+* Better message for invalid keywords/options in task due to undefined expressions
<a id="2.3.2"></a>
diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py
index a19a218c86..41b22c966a 100644
--- a/lib/ansible/playbook/base.py
+++ b/lib/ansible/playbook/base.py
@@ -29,7 +29,7 @@ from jinja2.exceptions import UndefinedError
from ansible.compat.six import iteritems, string_types, with_metaclass
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.constants import mk_boolean as boolean
@@ -444,8 +444,11 @@ class Base(with_metaclass(BaseMeta, object)):
" Error was: %s" % (name, value, attribute.isa, e), obj=self.get_ds())
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())
+ 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
diff --git a/test/units/playbook/test_base.py b/test/units/playbook/test_base.py
index 862d659d3a..39c14d27be 100644
--- a/test/units/playbook/test_base.py
+++ b/test/units/playbook/test_base.py
@@ -508,8 +508,8 @@ class TestBaseSubClass(TestBase):
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 }}'}