From 5561fbc42744d194d4daf77efa8a65fd5b705778 Mon Sep 17 00:00:00 2001 From: bryan hunt Date: Mon, 24 Mar 2014 13:51:44 +0000 Subject: [PATCH 1/3] Accept status code from a list of valid codes. --- network/uri | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/network/uri b/network/uri index 9a22d4758c8..ac12ffbb782 100644 --- a/network/uri +++ b/network/uri @@ -101,7 +101,7 @@ options: required: false status_code: description: - - A valid, numeric, HTTP status code that signifies success of the request. + - A valid, numeric, HTTP status code that signifies success of the request. Can also be comma separated list of status codes. required: false default: 200 timeout: @@ -315,7 +315,7 @@ def main(): follow_redirects = dict(required=False, default='no', type='bool'), creates = dict(required=False, default=None), removes = dict(required=False, default=None), - status_code = dict(required=False, default=200, type='int'), + status_code = dict(required=False, default=[200], type='list'), timeout = dict(required=False, default=30, type='int'), ), check_invalid_arguments=False, @@ -338,7 +338,7 @@ def main(): follow_redirects = module.params['follow_redirects'] creates = module.params['creates'] removes = module.params['removes'] - status_code = int(module.params['status_code']) + status_code = list(module.params['status_code']) socket_timeout = module.params['timeout'] # Grab all the http headers. Need this hack since passing multi-values is currently a bit ugly. (e.g. headers='{"Content-Type":"application/json"}') @@ -412,7 +412,11 @@ def main(): uresp['json'] = js except: pass - if resp['status'] != status_code: + + sys.stderr.write("status ----> %s \n" % resp['status']) + sys.stderr.write("status_code ----> %s \n" % status_code) + + if str(resp['status']) not in status_code: module.fail_json(msg="Status code was not " + str(status_code), content=content, **uresp) elif return_content: module.exit_json(changed=changed, content=content, **uresp) From eb9ac9308c362511dec0d55f0614e9a2c52fbb7e Mon Sep 17 00:00:00 2001 From: bryan hunt Date: Mon, 24 Mar 2014 14:17:36 +0000 Subject: [PATCH 2/3] Accept status code from a list of valid codes. --- network/uri | 4 ---- 1 file changed, 4 deletions(-) diff --git a/network/uri b/network/uri index ac12ffbb782..0d6cd7dc789 100644 --- a/network/uri +++ b/network/uri @@ -412,10 +412,6 @@ def main(): uresp['json'] = js except: pass - - sys.stderr.write("status ----> %s \n" % resp['status']) - sys.stderr.write("status_code ----> %s \n" % status_code) - if str(resp['status']) not in status_code: module.fail_json(msg="Status code was not " + str(status_code), content=content, **uresp) elif return_content: From dff1fd3b37bbc4c9ee38a44f2ae459165f3ce816 Mon Sep 17 00:00:00 2001 From: bryan hunt Date: Mon, 24 Mar 2014 14:23:18 +0000 Subject: [PATCH 3/3] Accept status code from a list of valid codes. (cast the list of acceptable codes to a list of int ) --- network/uri | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network/uri b/network/uri index 0d6cd7dc789..afc1dbd7f43 100644 --- a/network/uri +++ b/network/uri @@ -338,7 +338,7 @@ def main(): follow_redirects = module.params['follow_redirects'] creates = module.params['creates'] removes = module.params['removes'] - status_code = list(module.params['status_code']) + status_code = [int(x) for x in list(module.params['status_code'])] socket_timeout = module.params['timeout'] # Grab all the http headers. Need this hack since passing multi-values is currently a bit ugly. (e.g. headers='{"Content-Type":"application/json"}') @@ -412,7 +412,7 @@ def main(): uresp['json'] = js except: pass - if str(resp['status']) not in status_code: + if resp['status'] not in status_code: module.fail_json(msg="Status code was not " + str(status_code), content=content, **uresp) elif return_content: module.exit_json(changed=changed, content=content, **uresp)