1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

fixes for uri module

- clarify docs on body_json behaviour
- only tranform into json if body input is not a string
  users keep passing json string and expecint it to not be jsonified again
- fixed issue with removes not handling path expansion correctly
- switched all path variables to 'type path' to handle expansions
This commit is contained in:
Brian Coca 2016-02-11 01:09:20 -05:00 committed by Matt Clay
parent bc834ff564
commit 5b07831a11

View file

@ -63,12 +63,12 @@ options:
default: null default: null
body: body:
description: description:
- The body of the http request/response to the web service. - The body of the http request/response to the web service. If C(body_format) is set to 'json' it will take an already formated JSON string or convert a data structure into JSON.
required: false required: false
default: null default: null
body_format: body_format:
description: description:
- The serialization format of the body. Either raw, or json. When set to json, encodes the body argument and automatically sets the Content-Type header accordingly. - The serialization format of the body. When set to json, encodes the body argument, if needed, and automatically sets the Content-Type header accordingly.
required: false required: false
default: raw default: raw
version_added: "2.0" version_added: "2.0"
@ -368,7 +368,7 @@ def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec = dict(
url = dict(required=True), url = dict(required=True),
dest = dict(required=False, default=None), dest = dict(required=False, default=None, type='path'),
user = dict(required=False, default=None), user = dict(required=False, default=None),
password = dict(required=False, default=None), password = dict(required=False, default=None),
body = dict(required=False, default=None), body = dict(required=False, default=None),
@ -377,8 +377,8 @@ def main():
return_content = dict(required=False, default='no', type='bool'), return_content = dict(required=False, default='no', type='bool'),
force_basic_auth = dict(required=False, default='no', type='bool'), force_basic_auth = dict(required=False, default='no', type='bool'),
follow_redirects = dict(required=False, default='safe', choices=['all', 'safe', 'none', 'yes', 'no']), follow_redirects = dict(required=False, default='safe', choices=['all', 'safe', 'none', 'yes', 'no']),
creates = dict(required=False, default=None), creates = dict(required=False, default=None, type='path'),
removes = dict(required=False, default=None), removes = dict(required=False, default=None, type='path'),
status_code = dict(required=False, default=[200], type='list'), status_code = dict(required=False, default=[200], type='list'),
timeout = dict(required=False, default=30, type='int'), timeout = dict(required=False, default=30, type='int'),
validate_certs = dict(required=False, default=True, type='bool'), validate_certs = dict(required=False, default=True, type='bool'),
@ -396,7 +396,7 @@ def main():
user = module.params['user'] user = module.params['user']
password = module.params['password'] password = module.params['password']
body = module.params['body'] body = module.params['body']
body_format = module.params['body_format'] body_format = module.params['body_format'].lower()
method = module.params['method'] method = module.params['method']
dest = module.params['dest'] dest = module.params['dest']
return_content = module.params['return_content'] return_content = module.params['return_content']
@ -410,8 +410,9 @@ def main():
dict_headers = {} dict_headers = {}
# If body_format is json, encodes the body (wich can be a dict or a list) and automatically sets the Content-Type header
if body_format == 'json': if body_format == 'json':
# Encode the body unless its a string, then assume it is preformatted JSON
if not isinstance(body, basestring):
body = json.dumps(body) body = json.dumps(body)
dict_headers['Content-Type'] = 'application/json' dict_headers['Content-Type'] = 'application/json'
@ -427,7 +428,6 @@ def main():
# do not run the command if the line contains creates=filename # do not run the command if the line contains creates=filename
# and the filename already exists. This allows idempotence # and the filename already exists. This allows idempotence
# of uri executions. # of uri executions.
creates = os.path.expanduser(creates)
if os.path.exists(creates): if os.path.exists(creates):
module.exit_json(stdout="skipped, since %s exists" % creates, changed=False, stderr=False, rc=0) module.exit_json(stdout="skipped, since %s exists" % creates, changed=False, stderr=False, rc=0)
@ -435,7 +435,6 @@ def main():
# do not run the command if the line contains removes=filename # do not run the command if the line contains removes=filename
# and the filename do not exists. This allows idempotence # and the filename do not exists. This allows idempotence
# of uri executions. # of uri executions.
v = os.path.expanduser(removes)
if not os.path.exists(removes): if not os.path.exists(removes):
module.exit_json(stdout="skipped, since %s does not exist" % removes, changed=False, stderr=False, rc=0) module.exit_json(stdout="skipped, since %s does not exist" % removes, changed=False, stderr=False, rc=0)