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

Fix installation of standalone roles #1397

Merged
merged 1 commit into from Feb 21, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/ansiblelint/_prerun.py
Expand Up @@ -110,7 +110,7 @@ def prepare_environment() -> None:
"requirements.yml",
]

print("Running %s" % " ".join(cmd))
print("Running %s" % " ".join(cmd), file=sys.stderr)
run = subprocess.run(
cmd,
universal_newlines=True,
Expand All @@ -135,7 +135,7 @@ def prepare_environment() -> None:
"requirements.yml",
]

print("Running %s" % " ".join(cmd))
print("Running %s" % " ".join(cmd), file=sys.stderr)
run = subprocess.run(
cmd,
universal_newlines=True,
Expand All @@ -157,7 +157,7 @@ def _install_galaxy_role() -> None:
if not os.path.exists("meta/main.yml"):
return
yaml = yaml_from_file("meta/main.yml")
if 'galaxy_info' not in 'yaml':
if 'galaxy_info' not in yaml:
return
role_name = yaml['galaxy_info'].get('role_name', None)
role_author = yaml['galaxy_info'].get('author', None)
Expand All @@ -170,8 +170,14 @@ def _install_galaxy_role() -> None:
p = pathlib.Path(".cache/roles")
p.mkdir(parents=True, exist_ok=True)
link_path = p / f"{role_author}.{role_name}"
if not link_path.exists:
# despite documentation stating that is_file() reports true for symlinks,
# it appears that is_dir() reports true instead, so we rely on exits().
if not link_path.exists():
link_path.symlink_to(pathlib.Path("../..", target_is_directory=True))
print(
f"Using {link_path} symlink to current repository in order to enable Ansible to find the role using its expected full name.",
file=sys.stderr,
)


def _prepare_ansible_paths() -> None:
Expand Down
8 changes: 4 additions & 4 deletions test/test_prerun.py
Expand Up @@ -12,8 +12,8 @@ def test_prerun_reqs_v1() -> None:
)
)
result = run_ansible_lint(".", cwd=cwd)
assert "Running ansible-galaxy role install" in result.stdout
assert "Running ansible-galaxy collection install" not in result.stdout
assert "Running ansible-galaxy role install" in result.stderr
assert "Running ansible-galaxy collection install" not in result.stderr
assert result.returncode == 0


Expand All @@ -25,6 +25,6 @@ def test_prerun_reqs_v2() -> None:
)
)
result = run_ansible_lint(".", cwd=cwd)
assert "Running ansible-galaxy role install" in result.stdout
assert "Running ansible-galaxy collection install" in result.stdout
assert "Running ansible-galaxy role install" in result.stderr
assert "Running ansible-galaxy collection install" in result.stderr
assert result.returncode == 0