@ -332,13 +332,12 @@ def api_get_list(api_server, what):
# scm repo utility functions
#-------------------------------------------------------------------------------------
def scm_archive_role(scm, role_url, role_version):
def scm_archive_role(scm, role_url, role_version, role_name ):
if scm not in ['hg', 'git']:
print "SCM %s is not currently supported" % scm
return False
tempdir = tempfile.mkdtemp()
role_name = ansible.utils.repo_url_to_role_name(role_url)
clone_cmd = [scm, 'clone', role_url]
clone_cmd = [scm, 'clone', role_url, role_name]
with open('/dev/null', 'w') as devnull:
popen = subprocess.Popen(clone_cmd, cwd=tempdir, stdout=devnull, stderr=devnull)
rc = popen.wait()
@ -464,7 +463,10 @@ def fetch_role(role_name, target, role_data, options):
"""
# first grab the file and save it to a temp location
archive_url = 'https://github.com/%s/%s/archive/%s.tar.gz' % (role_data["github_user"], role_data["github_repo"], target)
if '://' in role_name:
archive_url = role_name
else:
archive_url = 'https://github.com/%s/%s/archive/%s.tar.gz' % (role_data["github_user"], role_data["github_repo"], target)
print " - downloading role from %s" % archive_url
try:
@ -706,39 +708,24 @@ def execute_install(args, options, parser):
while len(roles_left) > 0:
# query the galaxy API for the role data
role_name = roles_left.pop(0).strip()
role_version = None
if role_name == "" or role_name.startswith("#"):
continue
elif ',' in role_name:
role_name,role_version = role_name.split(',',1)
role_name = role_name.strip()
role_version = role_version.strip()
(scm, role_src, role_version, role_name) = ansible.utils.role_spec_parse(roles_left.pop(0))
role_data = None
if os.path.isfile(role_name ):
if os.path.isfile(role_src):
# installing a local tar.gz
tar_file = role_name
role_name = os.path.basename(role_name).replace('.tar.gz','')
if tarfile.is_tarfile(tar_file):
print " - installing %s as %s" % (tar_file, role_name)
if not install_role(role_name, role_version, tar_file, options):
exit_without_ignore(options)
else:
print "%s (%s) was NOT installed successfully." % (role_name,tar_file)
exit_without_ignore(options)
tmp_file = role_src
else:
if '+' in role_name:
(scm, role_url) = role_name.split('+',1)
role_name = ansible.utils.repo_url_to_role_name(role_name)
if scm:
# create tar file from scm url
tmp_file = scm_archive_role(scm, role_url, role_version)
role_data = None
tmp_file = scm_archive_role(scm, role_src, role_version, role_name)
elif '://' in role_src:
# just download a URL - version will probably be in the URL
tmp_file = fetch_role(role_src, None, None, options)
else:
# installing remotely
role_data = api_lookup_role_by_name(api_server, role_name )
# installing from galax y
role_data = api_lookup_role_by_name(api_server, role_src )
if not role_data:
print "Sorry, %s was not found on %s." % (role_name , api_server)
print "Sorry, %s was not found on %s." % (role_src , api_server)
continue
role_versions = api_fetch_role_related(api_server, 'versions', role_data['id'])
@ -762,29 +749,29 @@ def execute_install(args, options, parser):
# download the role. if --no-deps was specified, we stop here,
# otherwise we recursively grab roles and all of their deps.
tmp_file = fetch_role(role_name, role_version, role_data, options)
if tmp_file and install_role(role_name, role_version, tmp_file, options):
# we're done with the temp file, clean it up
os.unlink(tmp_file)
# install dependencies, if we want them
if not no_deps:
if not role_data:
role_data = get_role_metadata(role_name, options)
role_dependencies = role_data['dependencies']
tmp_file = fetch_role(role_src, role_version, role_data, options)
if tmp_file and install_role(role_name, role_version, tmp_file, options):
# we're done with the temp file, clean it up
os.unlink(tmp_file)
# install dependencies, if we want them
if not no_deps:
if not role_data:
role_data = get_role_metadata(role_name, options)
role_dependencies = role_data['dependencies']
else:
role_dependencies = role_data['summary_fields']['dependencies'] # api_fetch_role_related(api_server, 'dependencies', role_data['id'])
for dep_name in role_dependencies:
#dep_name = "%s.%s" % (dep['owner'], dep['name'])
if not get_role_metadata(dep_name.split('/')[-1], options):
print ' adding dependency: %s' % dep_name
roles_left.append(dep_name)
else:
role_dependencies = role_data['summary_fields']['dependencies'] # api_fetch_role_related(api_server, 'dependencies', role_data['id'])
for dep_name in role_dependencies:
#dep_name = "%s.%s" % (dep['owner'], dep['name'])
if not get_role_metadata(dep_name.split('/')[-1], options):
print ' adding dependency: %s' % dep_name
roles_left.append(dep_name)
else:
print ' dependency %s is already installed, skipping.' % dep_name
else:
if tmp_file:
os.unlink(tmp_file)
print "%s was NOT installed successfully." % role_name
exit_without_ignore(options)
print ' dependency %s is already installed, skipping.' % dep_name
else:
if tmp_file:
os.unlink(tmp_file)
print "%s was NOT installed successfully." % role_name
exit_without_ignore(options)
sys.exit(0)
def execute_remove(args, options, parser):