Skip to content

Commit

Permalink
Avoid pre-run errors when role-name is disabled
Browse files Browse the repository at this point in the history
- when `role-name` is added to skip_list, just install simple role name
- when `role-name` is added to warn_list, display warning and continue
  execution.

Fixes: #1454
  • Loading branch information
ssbarnea committed Mar 11, 2021
1 parent aa01b74 commit 9fe4114
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions .ansible-lint
Expand Up @@ -42,6 +42,7 @@ warn_list:
- skip_this_tag
- git-latest
- experimetal # experimental is included in the implicit list
# - role-name

# Offline mode disables installation of requirements.yml
offline: false
Expand Down
45 changes: 28 additions & 17 deletions src/ansiblelint/_prerun.py
Expand Up @@ -163,23 +163,34 @@ def _install_galaxy_role() -> None:
if not role_name:
role_name = pathlib.Path(".").absolute().name
role_name = re.sub(r'^{0}'.format(re.escape('ansible-role-')), '', role_name)
fqrn = f"{role_namespace}.{role_name}"
if not re.match(r"[a-z0-9][a-z0-9_]+\.[a-z][a-z0-9_]+$", fqrn):
_logger.error(
"""\
Computed fully qualified role name of %s is not valid.
Please edit meta/main.yml and assure we can correctly determine full role name:
galaxy_info:
role_name: my_name # if absent directory name hosting role is used instead
namespace: my_galaxy_namespace # if absent, author is used instead
Namespace: https://galaxy.ansible.com/docs/contributing/namespaces.html#galaxy-namespace-limitations
Role: https://galaxy.ansible.com/docs/contributing/creating_role.html#role-names
""",
fqrn,
)
sys.exit(INVALID_PREREQUISITES_RC)

if 'role-name' not in options.skip_list:
fqrn = f"{role_namespace}.{role_name}"
if not re.match(r"[a-z0-9][a-z0-9_]+\.[a-z][a-z0-9_]+$", fqrn):
msg = (
"""\
Computed fully qualified role name of %s does not follow current galaxy requirements.
Please edit meta/main.yml and assure we can correctly determine full role name:
galaxy_info:
role_name: my_name # if absent directory name hosting role is used instead
namespace: my_galaxy_namespace # if absent, author is used instead
Namespace: https://galaxy.ansible.com/docs/contributing/namespaces.html#galaxy-namespace-limitations
Role: https://galaxy.ansible.com/docs/contributing/creating_role.html#role-names
As an alternative, you can add 'role-name' to either skip_list or warn_list.
""",
fqrn,
)
if 'role-name' in options.warn_list:
_logger.warning(msg)
else:
_logger.error(msg)
sys.exit(INVALID_PREREQUISITES_RC)
else:
# when 'role-name' is in skip_list, we stick to plain role names
fqrn = role_name
p = pathlib.Path(f"{options.project_dir}/.cache/roles")
p.mkdir(parents=True, exist_ok=True)
link_path = p / f"{role_namespace}.{role_name}"
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/cli.py
Expand Up @@ -317,7 +317,7 @@ def merge_config(file_config: Dict[Any, Any], cli_config: Namespace) -> Namespac
'rulesdir': [],
'skip_list': [],
'tags': [],
'warn_list': ['experimental'],
'warn_list': ['experimental', 'role-name'],
'mock_modules': [],
'mock_roles': [],
'enable_list': [],
Expand Down

0 comments on commit 9fe4114

Please sign in to comment.