mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
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:
parent
4803e923ff
commit
46b59b02ed
6 changed files with 81 additions and 67 deletions
|
@ -356,10 +356,33 @@ def repo_url_to_role_name(repo_url):
|
|||
trailing_path = repo_url.split('/')[-1]
|
||||
if trailing_path.endswith('.git'):
|
||||
trailing_path = trailing_path[:-4]
|
||||
if trailing_path.endswith('.tar.gz'):
|
||||
trailing_path = trailing_path[:-7]
|
||||
if ',' in trailing_path:
|
||||
trailing_path = trailing_path.split(',')[0]
|
||||
return trailing_path
|
||||
|
||||
|
||||
def role_spec_parse(role_spec):
|
||||
role_spec = role_spec.strip()
|
||||
role_version = ''
|
||||
if role_spec == "" or role_spec.startswith("#"):
|
||||
return (None, None, None, None)
|
||||
tokens = map(lambda s: s.strip(), role_spec.split(','))
|
||||
if '+' in tokens[0]:
|
||||
(scm, role_url) = tokens[0].split('+')
|
||||
else:
|
||||
scm = None
|
||||
role_url = tokens[0]
|
||||
if len(tokens) >= 2:
|
||||
role_version = tokens[1]
|
||||
if len(tokens) == 3:
|
||||
role_name = tokens[2]
|
||||
else:
|
||||
role_name = repo_url_to_role_name(tokens[0])
|
||||
return (scm, role_url, role_version, role_name)
|
||||
|
||||
|
||||
def json_loads(data):
|
||||
''' parse a JSON string and return a data structure '''
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue