From 8153c34abf95e7cf061ad9d23e0dbe820aaba7ea Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 29 Jul 2015 19:48:21 -0400 Subject: [PATCH] now returns false on bad role_data --- lib/ansible/galaxy/role.py | 40 ++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/ansible/galaxy/role.py b/lib/ansible/galaxy/role.py index cac47fbb32b..3a58ccb6d1a 100644 --- a/lib/ansible/galaxy/role.py +++ b/lib/ansible/galaxy/role.py @@ -182,28 +182,30 @@ class GalaxyRole(object): """ Downloads the archived role from github to a temp location """ + if role_data: - # first grab the file and save it to a temp location - if "github_user" in role_data and "github_repo" in role_data: - archive_url = 'https://github.com/%s/%s/archive/%s.tar.gz' % (role_data["github_user"], role_data["github_repo"], self.version) - else: - archive_url = self.src - self.display.display("- downloading role from %s" % archive_url) + # first grab the file and save it to a temp location + if "github_user" in role_data and "github_repo" in role_data: + archive_url = 'https://github.com/%s/%s/archive/%s.tar.gz' % (role_data["github_user"], role_data["github_repo"], self.version) + else: + archive_url = self.src + self.display.display("- downloading role from %s" % archive_url) - try: - url_file = urlopen(archive_url) - temp_file = tempfile.NamedTemporaryFile(delete=False) - data = url_file.read() - while data: - temp_file.write(data) + try: + url_file = urlopen(archive_url) + temp_file = tempfile.NamedTemporaryFile(delete=False) data = url_file.read() - temp_file.close() - return temp_file.name - except: - # TODO: better urllib2 error handling for error - # messages that are more exact - self.display.error("failed to download the file.") - return False + while data: + temp_file.write(data) + data = url_file.read() + temp_file.close() + return temp_file.name + except: + # TODO: better urllib2 error handling for error + # messages that are more exact + self.display.error("failed to download the file.") + + return False def install(self, role_filename): # the file is a tar, so open it that way and extract it