From 62765858825173dd532827fe4c1dfb246eb8db47 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 10 Feb 2016 10:51:12 -0800 Subject: [PATCH] Module params should default to str in most cases. --- lib/ansible/module_utils/basic.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 4bb376c288..3c14af7fbb 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -226,7 +226,7 @@ except ImportError: FILE_COMMON_ARGUMENTS=dict( src = dict(), - mode = dict(), + mode = dict(type='raw'), owner = dict(), group = dict(), seuser = dict(), @@ -574,6 +574,7 @@ class AnsibleModule(object): 'int': self._check_type_int, 'float': self._check_type_float, 'path': self._check_type_path, + 'raw': self._check_type_raw, } if not bypass_checks: self._check_required_arguments() @@ -1360,15 +1361,23 @@ class AnsibleModule(object): value = self._check_type_str(value) return os.path.expanduser(os.path.expandvars(value)) + def _check_type_raw(self, value): + return value + def _check_argument_types(self): ''' ensure all arguments have the requested type ''' for (k, v) in self.argument_spec.items(): wanted = v.get('type', None) - if wanted is None: - continue if k not in self.params: 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]