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