1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Iterate through role paths when installing roles (#17487)

* Iterate through role paths when attempting to install roles
This commit is contained in:
jctanner 2016-09-09 16:50:50 -04:00 committed by GitHub
parent e8897a9b91
commit af2ce7725b

View file

@ -79,6 +79,9 @@ class GalaxyRole(object):
else: else:
# use the first path by default # use the first path by default
self.path = os.path.join(galaxy.roles_paths[0], self.name) self.path = os.path.join(galaxy.roles_paths[0], self.name)
# create list of possible paths
self.paths = [x for x in galaxy.roles_paths]
self.paths = [os.path.join(x, self.name) for x in self.paths]
def __eq__(self, other): def __eq__(self, other):
return self.name == other.name return self.name == other.name
@ -261,38 +264,49 @@ class GalaxyRole(object):
# we strip off the top-level directory for all of the files contained within # we strip off the top-level directory for all of the files contained within
# the tar file here, since the default is 'github_repo-target', and change it # the tar file here, since the default is 'github_repo-target', and change it
# to the specified role's name # to the specified role's name
display.display("- extracting %s to %s" % (self.name, self.path)) installed = False
try: while not installed:
if os.path.exists(self.path): display.display("- extracting %s to %s" % (self.name, self.path))
if not os.path.isdir(self.path): try:
raise AnsibleError("the specified roles path exists and is not a directory.") if os.path.exists(self.path):
elif not getattr(self.options, "force", False): if not os.path.isdir(self.path):
raise AnsibleError("the specified role %s appears to already exist. Use --force to replace it." % self.name) raise AnsibleError("the specified roles path exists and is not a directory.")
elif not getattr(self.options, "force", False):
raise AnsibleError("the specified role %s appears to already exist. Use --force to replace it." % self.name)
else:
# using --force, remove the old path
if not self.remove():
raise AnsibleError("%s doesn't appear to contain a role.\n please remove this directory manually if you really want to put the role here." % self.path)
else: else:
# using --force, remove the old path os.makedirs(self.path)
if not self.remove():
raise AnsibleError("%s doesn't appear to contain a role.\n please remove this directory manually if you really want to put the role here." % self.path)
else:
os.makedirs(self.path)
# now we do the actual extraction to the path # now we do the actual extraction to the path
for member in members: for member in members:
# we only extract files, and remove any relative path # we only extract files, and remove any relative path
# bits that might be in the file for security purposes # bits that might be in the file for security purposes
# and drop the leading directory, as mentioned above # and drop the leading directory, as mentioned above
if member.isreg() or member.issym(): if member.isreg() or member.issym():
parts = member.name.split(os.sep)[1:] parts = member.name.split(os.sep)[1:]
final_parts = [] final_parts = []
for part in parts: for part in parts:
if part != '..' and '~' not in part and '$' not in part: if part != '..' and '~' not in part and '$' not in part:
final_parts.append(part) final_parts.append(part)
member.name = os.path.join(*final_parts) member.name = os.path.join(*final_parts)
role_tar_file.extract(member, self.path) role_tar_file.extract(member, self.path)
# write out the install info file for later use # write out the install info file for later use
self._write_galaxy_install_info() self._write_galaxy_install_info()
except OSError as e: installed = True
raise AnsibleError("Could not update files in %s: %s" % (self.path, str(e))) except OSError as e:
error = True
if e[0] == 13 and len(self.paths) > 1:
current = self.paths.index(self.path)
nextidx = current + 1
if len(self.paths) >= current:
self.path = self.paths[nextidx]
error = False
if error:
raise AnsibleError("Could not update files in %s: %s" % (self.path, str(e)))
# return the parsed yaml metadata # return the parsed yaml metadata
display.display("- %s was installed successfully" % self.name) display.display("- %s was installed successfully" % self.name)