From 86a63cfcd7f0c5fc2dd6969a9df2e62bc94f6c58 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 26 Apr 2017 21:05:40 +0530 Subject: [PATCH] Handle fetch_url error gracefully (#23821) Fix adds http response code check for fetch_url. Also, method in fetch_url call. Fixes https://github.com/ansible/ansible/issues/23800 Signed-off-by: Abhijeet Kasurde --- lib/ansible/modules/packaging/os/apt.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/packaging/os/apt.py b/lib/ansible/modules/packaging/os/apt.py index a88cd5f398..4da86770fe 100644 --- a/lib/ansible/modules/packaging/os/apt.py +++ b/lib/ansible/modules/packaging/os/apt.py @@ -722,7 +722,10 @@ def download(module, deb): BUFSIZE = 65536 try: - rsp, info = fetch_url(module, deb) + rsp, info = fetch_url(module, deb, method='GET') + if info['status'] != 200: + module.fail_json(msg="Failed to download %s, %s" % (deb, + info['msg'])) # Ensure file is open in binary mode for Python 3 f = open(package, 'wb') # Read 1kb at a time to save on ram