Skip to content

Commit 90fb69a

Browse files
Look for ansible binary in the same path the linter (#3903)
1 parent b0b1e69 commit 90fb69a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/ansiblelint/__main__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def fix(runtime_options: Options, result: LintResult, rules: RulesCollection) ->
285285
def main(argv: list[str] | None = None) -> int:
286286
"""Linter CLI entry point."""
287287
# alter PATH if needed (venv support)
288-
path_inject()
288+
path_inject(argv[0] if argv and argv[0] else "")
289289

290290
if argv is None: # pragma: no cover
291291
argv = sys.argv
@@ -410,7 +410,7 @@ def _run_cli_entrypoint() -> None:
410410
raise SystemExit(exc) from exc
411411

412412

413-
def path_inject() -> None:
413+
def path_inject(own_location: str = "") -> None:
414414
"""Add python interpreter path to top of PATH to fix outside venv calling."""
415415
# This make it possible to call ansible-lint that was installed inside a
416416
# virtualenv without having to pre-activate it. Otherwise subprocess will
@@ -451,6 +451,14 @@ def path_inject() -> None:
451451
):
452452
inject_paths.append(str(py_path))
453453

454+
# last option, if nothing else is found, just look next to ourselves...
455+
if (
456+
own_location
457+
and (Path(own_location).parent / "ansible").exists()
458+
and str(Path(own_location).parent) not in paths
459+
):
460+
inject_paths.append(str(Path(own_location).parent))
461+
454462
if not os.environ.get("PYENV_VIRTUAL_ENV", None):
455463
if inject_paths:
456464
print( # noqa: T201

0 commit comments

Comments
 (0)