summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag Wieers <dag@wieers.com>2016-11-18 14:36:31 +0100
committerToshio Kuratomi <a.badger@gmail.com>2016-11-21 12:40:14 -0800
commitc71b4aad22c4a7e35a7a065d776d020521f24ae5 (patch)
tree59770647473350ac479a5f9ff9bdb47d1c4019c3
parent663ba5275a9a0ba9ca65709b4ea24469e3efb501 (diff)
downloadansible-modules-core-c71b4aad22c4a7e35a7a065d776d020521f24ae5.tar.gz
Ensure proper error when fetch_url returns status -1
When using a file:// or ftp:// URL the normal provisions that a non-200 status code means error have been disabled. But the common error status -1 from fetch_url is not properly returning an error message. This fix ensures that if the status code returns -1, we return a proper error message. This fixes #3563 (cherry picked from commit 7903b39fc0c1e7559c98b838e4da5bc157a24412)
-rw-r--r--network/basics/get_url.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/network/basics/get_url.py b/network/basics/get_url.py
index d2c8da12..e7a5860b 100644
--- a/network/basics/get_url.py
+++ b/network/basics/get_url.py
@@ -227,10 +227,14 @@ def url_get(module, url, dest, use_proxy, last_mod_time, force, timeout=10, head
if info['status'] == 304:
module.exit_json(url=url, dest=dest, changed=False, msg=info.get('msg', ''))
- # create a temporary file and copy content to do checksum-based replacement
+ # Exceptions in fetch_url may result in a status -1, the ensures a proper error to the user in all cases
+ if info['status'] == -1:
+ module.fail_json(msg=info['msg'], url=url, dest=dest)
+
if info['status'] != 200 and not url.startswith('file:/') and not (url.startswith('ftp:/') and info.get('msg', '').startswith('OK')):
module.fail_json(msg="Request failed", status_code=info['status'], response=info['msg'], url=url, dest=dest)
+ # create a temporary file and copy content to do checksum-based replacement
if tmp_dest != '':
# tmp_dest should be an existing dir
tmp_dest_is_dir = os.path.isdir(tmp_dest)