Skip to content

Commit

Permalink
Find and lint imported playbooks (#3413)
Browse files Browse the repository at this point in the history
  • Loading branch information
audgirka authored May 9, 2023
1 parent 8c80975 commit 9ad441c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 795
PYTEST_REQPASS: 796
steps:
- name: Activate WSL1
if: "contains(matrix.shell, 'wsl')"
Expand Down
4 changes: 4 additions & 0 deletions examples/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
# site.yml
- ansible.builtin.import_playbook: playbooks/play.yml
- ansible.builtin.import_playbook: playbooks/playbook-parent.yml
6 changes: 5 additions & 1 deletion src/ansiblelint/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ def __init__(

def _guess_kind(self) -> None:
if self.kind == "yaml":
if isinstance(self.data, list) and "hosts" in self.data[0]:
if isinstance(self.data, list) and (
"hosts" in self.data[0]
or "import_playbook" in self.data[0]
or "ansible.builtin.import_playbook" in self.data[0]
):
if "rules" not in self.data[0]:
self.kind = "playbook"
else:
Expand Down
5 changes: 5 additions & 0 deletions test/test_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ def test_discover_lintables_umlaut(monkeypatch: MonkeyPatch) -> None:
id="41",
),
pytest.param("examples/playbooks/tasks/vars/bug-3289.yml", "vars", id="42"),
pytest.param(
"examples/site.yml",
"playbook",
id="43",
), # content should determine it as a play
),
)
def test_kinds(monkeypatch: MonkeyPatch, path: str, kind: FileType) -> None:
Expand Down

0 comments on commit 9ad441c

Please sign in to comment.