summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2016-02-10 10:51:12 -0800
committerToshio Kuratomi <toshio@fedoraproject.org>2016-02-10 12:21:32 -0800
commitba0047a3429738f70e2829216ad4d7694c1f1e54 (patch)
tree191c8a0ec7b00251feac24444791871075b5b700
parent371c7315b07a6b6cac127ba284d8e8d37734be2a (diff)
downloadansible-params-default-to-str.tar.gz
Module params should default to str in most cases.params-default-to-str
-rw-r--r--lib/ansible/module_utils/basic.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py
index 4bb376c288..5913d5dbb4 100644
--- a/lib/ansible/module_utils/basic.py
+++ b/lib/ansible/module_utils/basic.py
@@ -1365,10 +1365,15 @@ class AnsibleModule(object):
''' 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]