Friendly Role Names and roles from URLs

* Roles can now be given a friendly name as third field in role spec csv
* Roles can be installed from URL (not just from archived SCMs)
* Integration tests to demonstrate this
* Unit tests to ensure that role spec parsing works as expected
This commit is contained in:
Will Thames 2014-08-15 21:19:40 +10:00 committed by Michael DeHaan
commit 46b59b02ed
6 changed files with 81 additions and 67 deletions

View file

@ -178,13 +178,6 @@ class Play(object):
returns any variables that were included with the role
"""
orig_path = template(self.basedir,role,self.vars)
if '+' in orig_path and '://' in orig_path:
# dependency name pointing to SCM URL
# assume role name is last part of the URL
orig_path = utils.repo_url_to_role_name(orig_path)
if ',' in orig_path:
# version information for role dependency used by galaxy
orig_path = orig_path.split(',')[0]
role_vars = {}
if type(orig_path) == dict:
@ -193,20 +186,21 @@ class Play(object):
if role_name is None:
raise errors.AnsibleError("expected a role name in dictionary: %s" % orig_path)
role_vars = orig_path
orig_path = role_name
else:
(scm, role_src, role_version, role_name) = utils.role_spec_parse(orig_path)
role_path = None
possible_paths = [
utils.path_dwim(self.basedir, os.path.join('roles', orig_path)),
utils.path_dwim(self.basedir, orig_path)
utils.path_dwim(self.basedir, os.path.join('roles', role_name)),
utils.path_dwim(self.basedir, role_name)
]
if C.DEFAULT_ROLES_PATH:
search_locations = C.DEFAULT_ROLES_PATH.split(os.pathsep)
for loc in search_locations:
loc = os.path.expanduser(loc)
possible_paths.append(utils.path_dwim(loc, orig_path))
possible_paths.append(utils.path_dwim(loc, role_name))
for path_option in possible_paths:
if os.path.isdir(path_option):
@ -419,8 +413,7 @@ class Play(object):
role_name = role['role']
else:
role_name = role
if '+' in role_name and '://' in role_name:
role_name = utils.repo_url_to_role_name(role_name)
(scm, role_src, role_version, role_name) = utils.role_spec_parse(role_name)
role_names.append(role_name)
if os.path.isfile(task):