Skip to content

Commit 6276585

Browse files
committed
Module params should default to str in most cases.
1 parent 64c976a commit 6276585

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/ansible/module_utils/basic.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def _convert(node):
226226

227227
FILE_COMMON_ARGUMENTS=dict(
228228
src = dict(),
229-
mode = dict(),
229+
mode = dict(type='raw'),
230230
owner = dict(),
231231
group = dict(),
232232
seuser = dict(),
@@ -574,6 +574,7 @@ def __init__(self, argument_spec, bypass_checks=False, no_log=False,
574574
'int': self._check_type_int,
575575
'float': self._check_type_float,
576576
'path': self._check_type_path,
577+
'raw': self._check_type_raw,
577578
}
578579
if not bypass_checks:
579580
self._check_required_arguments()
@@ -1360,15 +1361,23 @@ def _check_type_path(self, value):
13601361
value = self._check_type_str(value)
13611362
return os.path.expanduser(os.path.expandvars(value))
13621363

1364+
def _check_type_raw(self, value):
1365+
return value
1366+
13631367

13641368
def _check_argument_types(self):
13651369
''' ensure all arguments have the requested type '''
13661370
for (k, v) in self.argument_spec.items():
13671371
wanted = v.get('type', None)
1368-
if wanted is None:
1369-
continue
13701372
if k not in self.params:
13711373
continue
1374+
if wanted is None:
1375+
# Mostly we want to default to str.
1376+
# For values set to None explicitly, return None instead as
1377+
# that allows a user to unset a parameter
1378+
if self.params[k] is None:
1379+
continue
1380+
wanted = 'str'
13721381

13731382
value = self.params[k]
13741383

0 commit comments

Comments
 (0)