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

basic: fix ValueError if value of a type='int' is not an int

With this fix, we get a friendly error message:

    failed: [localhost] => {"failed": true}
    msg: value of argument start_port is not of type int and we were unable to automatically convert
This commit is contained in:
Rene Moser 2015-05-19 17:34:39 +02:00
parent da6d15d1f9
commit 8f29ca23ae

View file

@ -1015,6 +1015,7 @@ class AnsibleModule(object):
value = self.params[k]
is_invalid = False
try:
if wanted == 'str':
if not isinstance(value, basestring):
self.params[k] = str(value)
@ -1066,6 +1067,8 @@ class AnsibleModule(object):
if is_invalid:
self.fail_json(msg="argument %s is of invalid type: %s, required: %s" % (k, type(value), wanted))
except ValueError, e:
self.fail_json(msg="value of argument %s is not of type %s and we were unable to automatically convert" % (k, wanted))
def _set_defaults(self, pre=True):
for (k,v) in self.argument_spec.iteritems():