Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid pre-run errors when role-name is disabled #1459

Merged
merged 1 commit into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
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
47 changes: 29 additions & 18 deletions src/ansiblelint/_prerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def prepare_environment() -> None:
stderr=subprocess.STDOUT,
)
if run.returncode != 0:
_logger.error(run.stdout, file=sys.stderr)
_logger.error(run.stdout)
sys.exit(run.returncode)

_install_galaxy_role()
Expand All @@ -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
Original file line number Diff line number Diff line change
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