Skip to content

Commit

Permalink
Fixes installation of standalone roles
Browse files Browse the repository at this point in the history
- correct two bugs that prevented standalone roles symlinks from
  being correctly created
- adds extra logging
- assure pre-run steps log to stderr
  • Loading branch information
ssbarnea committed Feb 21, 2021
1 parent 2ea1b79 commit 4b9cf46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
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

0 comments on commit 4b9cf46

Please sign in to comment.