From 35fef6fb845db76ec2128e0a72f6f433e8c57898 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Mon, 19 Dec 2016 17:55:12 -0500 Subject: [PATCH] Better error message for module unsupported params Keep track of all the unsupported parameters, and include all of them in the error message as well as a list of the supported params. --- lib/ansible/module_utils/basic.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 2ad55f0e170..9535a346cd9 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -727,7 +727,6 @@ class AnsibleModule(object): self._set_defaults(pre=True) - self._CHECK_ARGUMENT_TYPES_DISPATCHER = { 'str': self._check_type_str, 'list': self._check_type_list, @@ -1355,6 +1354,7 @@ class AnsibleModule(object): def _check_arguments(self, check_invalid_arguments): self._syslog_facility = 'LOG_USER' + unsupported_parameters = set() for (k,v) in list(self.params.items()): if k == '_ansible_check_mode' and v: @@ -1385,12 +1385,16 @@ class AnsibleModule(object): self._name = v elif check_invalid_arguments and k not in self._legal_inputs: - self.fail_json(msg="unsupported parameter for module: %s" % k) + unsupported_parameters.add(k) #clean up internal params: if k.startswith('_ansible_'): del self.params[k] + if unsupported_parameters: + self.fail_json(msg="Unsupported parameters for (%s) module: %s. Supported parameters include: %s" % (self._name, + ','.join(sorted(list(unsupported_parameters))), + ','.join(sorted(self.argument_spec.keys())))) if self.check_mode and not self.supports_check_mode: self.exit_json(skipped=True, msg="remote module (%s) does not support check mode" % self._name)