|
|
@ -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
|
|
|
|