Module params should default to str in most cases.

This commit is contained in:
Toshio Kuratomi 2016-02-10 10:51:12 -08:00
parent 64c976a6c3
commit 6276585882

View file

@ -226,7 +226,7 @@ except ImportError:
FILE_COMMON_ARGUMENTS=dict( FILE_COMMON_ARGUMENTS=dict(
src = dict(), src = dict(),
mode = dict(), mode = dict(type='raw'),
owner = dict(), owner = dict(),
group = dict(), group = dict(),
seuser = dict(), seuser = dict(),
@ -574,6 +574,7 @@ class AnsibleModule(object):
'int': self._check_type_int, 'int': self._check_type_int,
'float': self._check_type_float, 'float': self._check_type_float,
'path': self._check_type_path, 'path': self._check_type_path,
'raw': self._check_type_raw,
} }
if not bypass_checks: if not bypass_checks:
self._check_required_arguments() self._check_required_arguments()
@ -1360,15 +1361,23 @@ class AnsibleModule(object):
value = self._check_type_str(value) value = self._check_type_str(value)
return os.path.expanduser(os.path.expandvars(value)) return os.path.expanduser(os.path.expandvars(value))
def _check_type_raw(self, value):
return value
def _check_argument_types(self): def _check_argument_types(self):
''' ensure all arguments have the requested type ''' ''' ensure all arguments have the requested type '''
for (k, v) in self.argument_spec.items(): for (k, v) in self.argument_spec.items():
wanted = v.get('type', None) wanted = v.get('type', None)
if wanted is None:
continue
if k not in self.params: if k not in self.params:
continue continue
if wanted is None:
# Mostly we want to default to str.
# For values set to None explicitly, return None instead as
# that allows a user to unset a parameter
if self.params[k] is None:
continue
wanted = 'str'
value = self.params[k] value = self.params[k]