mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
format error messages from module_utils.basic nicer
* lists are printed as a string, separated by a comma and a space * require_if tells if is_one_of was True or False
This commit is contained in:
parent
c714da7fac
commit
0769460820
1 changed files with 12 additions and 9 deletions
|
@ -1621,7 +1621,7 @@ class AnsibleModule(object):
|
|||
for check in spec:
|
||||
count = self._count_terms(check, param)
|
||||
if count > 1:
|
||||
msg = "parameters are mutually exclusive: %s" % (check,)
|
||||
msg = "parameters are mutually exclusive: %s" % ', '.join(check)
|
||||
if self._options_context:
|
||||
msg += " found in %s" % " -> ".join(self._options_context)
|
||||
self.fail_json(msg=msg)
|
||||
|
@ -1645,7 +1645,7 @@ class AnsibleModule(object):
|
|||
non_zero = [c for c in counts if c > 0]
|
||||
if len(non_zero) > 0:
|
||||
if 0 in counts:
|
||||
msg = "parameters are required together: %s" % (check,)
|
||||
msg = "parameters are required together: %s" % ', '.join(check)
|
||||
if self._options_context:
|
||||
msg += " found in %s" % " -> ".join(self._options_context)
|
||||
self.fail_json(msg=msg)
|
||||
|
@ -1686,6 +1686,9 @@ class AnsibleModule(object):
|
|||
# present, else all requirements should be present.
|
||||
if is_one_of:
|
||||
max_missing_count = len(requirements)
|
||||
term = 'any'
|
||||
else:
|
||||
term = 'all'
|
||||
|
||||
if key in param and param[key] == val:
|
||||
for check in requirements:
|
||||
|
@ -1693,7 +1696,7 @@ class AnsibleModule(object):
|
|||
if count == 0:
|
||||
missing.append(check)
|
||||
if len(missing) and len(missing) >= max_missing_count:
|
||||
msg = "%s is %s but the following are missing: %s" % (key, val, ','.join(missing))
|
||||
msg = "%s is %s but %s of the following are missing: %s" % (key, val, ', '.join(missing))
|
||||
if self._options_context:
|
||||
msg += " found in %s" % " -> ".join(self._options_context)
|
||||
self.fail_json(msg=msg)
|
||||
|
|
Loading…
Reference in a new issue