Skip to content

Commit 483005e

Browse files
authored
Fixes installation of standalone roles (#1397)
- correct two bugs that prevented standalone roles symlinks from being correctly created - adds extra logging - assure pre-run steps log to stderr
1 parent 2ea1b79 commit 483005e

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/ansiblelint/_prerun.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def prepare_environment() -> None:
110110
"requirements.yml",
111111
]
112112

113-
print("Running %s" % " ".join(cmd))
113+
print("Running %s" % " ".join(cmd), file=sys.stderr)
114114
run = subprocess.run(
115115
cmd,
116116
universal_newlines=True,
@@ -135,7 +135,7 @@ def prepare_environment() -> None:
135135
"requirements.yml",
136136
]
137137

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

176182

177183
def _prepare_ansible_paths() -> None:

test/test_prerun.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def test_prerun_reqs_v1() -> None:
1212
)
1313
)
1414
result = run_ansible_lint(".", cwd=cwd)
15-
assert "Running ansible-galaxy role install" in result.stdout
16-
assert "Running ansible-galaxy collection install" not in result.stdout
15+
assert "Running ansible-galaxy role install" in result.stderr
16+
assert "Running ansible-galaxy collection install" not in result.stderr
1717
assert result.returncode == 0
1818

1919

@@ -25,6 +25,6 @@ def test_prerun_reqs_v2() -> None:
2525
)
2626
)
2727
result = run_ansible_lint(".", cwd=cwd)
28-
assert "Running ansible-galaxy role install" in result.stdout
29-
assert "Running ansible-galaxy collection install" in result.stdout
28+
assert "Running ansible-galaxy role install" in result.stderr
29+
assert "Running ansible-galaxy collection install" in result.stderr
3030
assert result.returncode == 0

0 commit comments

Comments
 (0)