removed dupe install code, now trap errors forom role.install

This commit is contained in:
Brian Coca 2015-10-05 13:03:34 -04:00
parent f73329401b
commit 6f88f79de9

View file

@ -340,69 +340,29 @@ class GalaxyCLI(CLI):
self.display.display('- %s is already installed, skipping.' % role.name)
continue
tmp_file = None
installed = False
if role.src and os.path.isfile(role.src):
# installing a local tar.gz
tmp_file = role.src
else:
if role.scm:
# create tar file from scm url
tmp_file = RoleRequirement.scm_archive_role(role.scm, role.src, role.version, role.name)
if role.src:
if '://' not in role.src:
role_data = self.api.lookup_role_by_name(role.src)
if not role_data:
self.display.warning("- sorry, %s was not found on %s." % (role.src, self.options.api_server))
self.exit_without_ignore()
continue
try:
installed = role.install()
except AnsibleError as e:
self.display.warning("- %s was NOT installed successfully: %s " % (role.name, str(e)))
self.exit_without_ignore()
continue
role_versions = self.api.fetch_role_related('versions', role_data['id'])
if not role.version:
# convert the version names to LooseVersion objects
# and sort them to get the latest version. If there
# are no versions in the list, we'll grab the head
# of the master branch
if len(role_versions) > 0:
loose_versions = [LooseVersion(a.get('name',None)) for a in role_versions]
loose_versions.sort()
role.version = str(loose_versions[-1])
else:
role.version = 'master'
elif role.version != 'master':
if role_versions and role.version not in [a.get('name', None) for a in role_versions]:
self.display.warning('role is %s' % role)
self.display.warning("- the specified version (%s) was not found in the list of available versions (%s)." % (role.version, role_versions))
self.exit_without_ignore()
continue
# download the role. if --no-deps was specified, we stop here,
# otherwise we recursively grab roles and all of their deps.
tmp_file = role.fetch(role_data)
if tmp_file:
self.display.debug('using %s' % tmp_file)
installed = role.install(tmp_file)
# we're done with the temp file, clean it up if we created it
if tmp_file != role.src:
os.unlink(tmp_file)
# install dependencies, if we want them
if not no_deps and installed:
role_dependencies = role.metadata.get('dependencies', [])
for dep in role_dependencies:
self.display.debug('Installing dep %s' % dep)
dep_req = RoleRequirement()
__, dep_name, __ = dep_req.parse(dep)
dep_role = GalaxyRole(self.galaxy, name=dep_name)
if dep_role.install_info is None or force:
if dep_role not in roles_left:
self.display.display('- adding dependency: %s' % dep_name)
roles_left.append(GalaxyRole(self.galaxy, name=dep_name))
else:
self.display.display('- dependency %s already pending installation.' % dep_name)
# install dependencies, if we want them
if not no_deps and installed:
role_dependencies = role.metadata.get('dependencies', [])
for dep in role_dependencies:
self.display.debug('Installing dep %s' % dep)
dep_req = RoleRequirement()
__, dep_name, __ = dep_req.parse(dep)
dep_role = GalaxyRole(self.galaxy, name=dep_name)
if dep_role.install_info is None or force:
if dep_role not in roles_left:
self.display.display('- adding dependency: %s' % dep_name)
roles_left.append(GalaxyRole(self.galaxy, name=dep_name))
else:
self.display.display('- dependency %s is already installed, skipping.' % dep_name)
self.display.display('- dependency %s already pending installation.' % dep_name)
else:
self.display.display('- dependency %s is already installed, skipping.' % dep_name)
if not installed:
self.display.warning("- %s was NOT installed successfully." % role.name)