diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2016-05-03 07:21:00 -0700 |
---|---|---|
committer | Brian Coca <bcoca@ansible.com> | 2016-05-03 10:21:00 -0400 |
commit | 3f104dcee9f6c0da9dd9c6c045979edf999ea929 (patch) | |
tree | 31d11c0c5b02cc6d7801b918b1029b9c6f0363b0 | |
parent | 52a714143ffec08785a98732c352ce8048ddaeb2 (diff) | |
download | ansible-3f104dcee9f6c0da9dd9c6c045979edf999ea929.tar.gz |
Add a jsonarg type to arg spec (#15701)
This makes sure that if we get a list or dict that it is turned into
a jsonified string.
-rw-r--r-- | lib/ansible/module_utils/basic.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index a8356d95a7..d8ab7a6b15 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -609,6 +609,7 @@ class AnsibleModule(object): 'float': self._check_type_float, 'path': self._check_type_path, 'raw': self._check_type_raw, + 'jsonarg': self._check_type_jsonarg, } if not bypass_checks: self._check_required_arguments() @@ -1395,6 +1396,16 @@ class AnsibleModule(object): value = self._check_type_str(value) return os.path.expanduser(os.path.expandvars(value)) + def _check_type_jsonarg(self, value): + # Return a jsonified string. Sometimes the controller turns a json + # string into a dict/list so transform it back into json here + if isinstance(value, (unicode, bytes)): + return value + else: + if isinstance(value (list, tuple, dict)): + return json.dumps(value) + raise TypeError('%s cannot be converted to a json string' % type(value)) + def _check_type_raw(self, value): return value |