mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
This commit is contained in:
parent
f7d79d4789
commit
e224039586
3 changed files with 21 additions and 16 deletions
|
@ -91,6 +91,8 @@ class GalaxyCLI(CLI):
|
||||||
help='Ignore errors and continue with the next specified role.')
|
help='Ignore errors and continue with the next specified role.')
|
||||||
self.parser.add_option('-n', '--no-deps', dest='no_deps', action='store_true', default=False, help='Don\'t download roles listed as dependencies')
|
self.parser.add_option('-n', '--no-deps', dest='no_deps', action='store_true', default=False, help='Don\'t download roles listed as dependencies')
|
||||||
self.parser.add_option('-r', '--role-file', dest='role_file', help='A file containing a list of roles to be imported')
|
self.parser.add_option('-r', '--role-file', dest='role_file', help='A file containing a list of roles to be imported')
|
||||||
|
self.parser.add_option('-g', '--keep-scm-meta', dest='keep_scm_meta', action='store_true',
|
||||||
|
default=False, help='Use tar instead of the scm archive option when packaging the role')
|
||||||
elif self.action == "remove":
|
elif self.action == "remove":
|
||||||
self.parser.set_usage("usage: %prog remove role1 role2 ...")
|
self.parser.set_usage("usage: %prog remove role1 role2 ...")
|
||||||
elif self.action == "list":
|
elif self.action == "list":
|
||||||
|
|
|
@ -194,17 +194,12 @@ class GalaxyRole(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
# the file is a tar, so open it that way and extract it
|
|
||||||
# to the specified (or default) roles directory
|
|
||||||
local_file = False
|
|
||||||
|
|
||||||
if self.scm:
|
if self.scm:
|
||||||
# create tar file from scm url
|
# create tar file from scm url
|
||||||
tmp_file = RoleRequirement.scm_archive_role(**self.spec)
|
tmp_file = RoleRequirement.scm_archive_role(keep_scm_meta=self.options.keep_scm_meta, **self.spec)
|
||||||
elif self.src:
|
elif self.src:
|
||||||
if os.path.isfile(self.src):
|
if os.path.isfile(self.src):
|
||||||
# installing a local tar.gz
|
|
||||||
local_file = True
|
|
||||||
tmp_file = self.src
|
tmp_file = self.src
|
||||||
elif '://' in self.src:
|
elif '://' in self.src:
|
||||||
role_data = self.src
|
role_data = self.src
|
||||||
|
@ -337,7 +332,7 @@ class GalaxyRole(object):
|
||||||
|
|
||||||
# return the parsed yaml metadata
|
# return the parsed yaml metadata
|
||||||
display.display("- %s was installed successfully" % str(self))
|
display.display("- %s was installed successfully" % str(self))
|
||||||
if not local_file:
|
if not (self.src and os.path.isfile(self.src)):
|
||||||
try:
|
try:
|
||||||
os.unlink(tmp_file)
|
os.unlink(tmp_file)
|
||||||
except (OSError, IOError) as e:
|
except (OSError, IOError) as e:
|
||||||
|
|
|
@ -23,6 +23,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import tarfile
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
|
@ -182,7 +183,7 @@ class RoleRequirement(RoleDefinition):
|
||||||
return role
|
return role
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def scm_archive_role(src, scm='git', name=None, version='HEAD'):
|
def scm_archive_role(src, scm='git', name=None, version='HEAD', keep_scm_meta=False):
|
||||||
if scm not in ['hg', 'git']:
|
if scm not in ['hg', 'git']:
|
||||||
raise AnsibleError("- scm %s is not currently supported" % scm)
|
raise AnsibleError("- scm %s is not currently supported" % scm)
|
||||||
tempdir = tempfile.mkdtemp()
|
tempdir = tempfile.mkdtemp()
|
||||||
|
@ -208,24 +209,31 @@ class RoleRequirement(RoleDefinition):
|
||||||
raise AnsibleError("- command %s failed in directory %s (rc=%s)" % (' '.join(checkout_cmd), tempdir, rc))
|
raise AnsibleError("- command %s failed in directory %s (rc=%s)" % (' '.join(checkout_cmd), tempdir, rc))
|
||||||
|
|
||||||
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.tar')
|
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.tar')
|
||||||
if scm == 'hg':
|
archive_cmd = None
|
||||||
|
if keep_scm_meta:
|
||||||
|
display.vvv('tarring %s from %s to %s' % (name, tempdir, temp_file.name))
|
||||||
|
with tarfile.open(temp_file.name, "w") as tar:
|
||||||
|
tar.add(os.path.join(tempdir, name), arcname=name)
|
||||||
|
elif scm == 'hg':
|
||||||
archive_cmd = ['hg', 'archive', '--prefix', "%s/" % name]
|
archive_cmd = ['hg', 'archive', '--prefix', "%s/" % name]
|
||||||
if version:
|
if version:
|
||||||
archive_cmd.extend(['-r', version])
|
archive_cmd.extend(['-r', version])
|
||||||
archive_cmd.append(temp_file.name)
|
archive_cmd.append(temp_file.name)
|
||||||
if scm == 'git':
|
elif scm == 'git':
|
||||||
archive_cmd = ['git', 'archive', '--prefix=%s/' % name, '--output=%s' % temp_file.name]
|
archive_cmd = ['git', 'archive', '--prefix=%s/' % name, '--output=%s' % temp_file.name]
|
||||||
if version:
|
if version:
|
||||||
archive_cmd.append(version)
|
archive_cmd.append(version)
|
||||||
else:
|
else:
|
||||||
archive_cmd.append('HEAD')
|
archive_cmd.append('HEAD')
|
||||||
|
|
||||||
with open('/dev/null', 'w') as devnull:
|
if archive_cmd is not None:
|
||||||
popen = subprocess.Popen(archive_cmd, cwd=os.path.join(tempdir, name),
|
display.vvv('archiving %s' % archive_cmd)
|
||||||
stderr=devnull, stdout=devnull)
|
with open('/dev/null', 'w') as devnull:
|
||||||
rc = popen.wait()
|
popen = subprocess.Popen(archive_cmd, cwd=os.path.join(tempdir, name),
|
||||||
if rc != 0:
|
stderr=devnull, stdout=devnull)
|
||||||
raise AnsibleError("- command %s failed in directory %s (rc=%s)" % (' '.join(archive_cmd), tempdir, rc))
|
rc = popen.wait()
|
||||||
|
if rc != 0:
|
||||||
|
raise AnsibleError("- command %s failed in directory %s (rc=%s)" % (' '.join(archive_cmd), tempdir, rc))
|
||||||
|
|
||||||
shutil.rmtree(tempdir, ignore_errors=True)
|
shutil.rmtree(tempdir, ignore_errors=True)
|
||||||
return temp_file.name
|
return temp_file.name
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue