Skip to content

Commit

Permalink
Merge branch 'main' into fix-wrapped-trailing-space
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonlhart committed Aug 16, 2024
2 parents 685965c + 5020961 commit d1ea782
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions examples/playbooks/import-failed-syntax-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: Import syntax-error.yml playbook
import_playbook: syntax-error.yml
3 changes: 3 additions & 0 deletions examples/playbooks/import-nonexistent-playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: Import nonexistent playbook
import_playbook: i-do-not-exist.yml
11 changes: 6 additions & 5 deletions src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,12 @@ def include_children( # pylint: disable=too-many-return-statements

if k in ("import_playbook", "ansible.builtin.import_playbook"):
included = Path(basedir) / v
if self.app.runtime.has_playbook(v, basedir=Path(basedir)):
if included.exists():
return [Lintable(included, kind=parent_type)]
return []
msg = f"Failed to find {v} playbook."
if not included.exists():
msg = f"Failed to find {v} playbook."
elif not self.app.runtime.has_playbook(v, basedir=Path(basedir)):
msg = f"Failed to load {v} playbook due to failing syntax check."
else:
return [Lintable(included, kind=parent_type)]
logging.error(msg)
return []

Expand Down
13 changes: 13 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from ansiblelint.constants import RC
from ansiblelint.file_utils import Lintable, cwd
from ansiblelint.runner import Runner
from ansiblelint.testing import run_ansible_lint

if TYPE_CHECKING:
from collections.abc import Sequence
Expand Down Expand Up @@ -490,3 +491,15 @@ def test_find_children_in_playbook(default_rules_collection: RulesCollection) ->
).find_children(lintable)
assert len(children) == 1
assert children[0].role == "bug4095"


def test_include_children_load_playbook_failed_syntax_check() -> None:
"""Verify include_children() logs playbook failed to load due to syntax-check."""
result = run_ansible_lint(
Path("playbooks/import-failed-syntax-check.yml"),
cwd=Path(__file__).resolve().parent.parent / "examples",
)
assert (
"Failed to load syntax-error.yml playbook due to failing syntax check."
in result.stderr
)

0 comments on commit d1ea782

Please sign in to comment.