From 9ad441c7d7090db1bcd5bdb3af1d2c72468023ad Mon Sep 17 00:00:00 2001 From: Ajinkya Udgirkar Date: Tue, 9 May 2023 15:03:15 +0530 Subject: [PATCH] Find and lint imported playbooks (#3413) --- .github/workflows/tox.yml | 2 +- examples/site.yml | 4 ++++ src/ansiblelint/file_utils.py | 6 +++++- test/test_file_utils.py | 5 +++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 examples/site.yml diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 6c9be82771..2bb376e9b8 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -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')" diff --git a/examples/site.yml b/examples/site.yml new file mode 100644 index 0000000000..dff8dd639e --- /dev/null +++ b/examples/site.yml @@ -0,0 +1,4 @@ +--- +# site.yml +- ansible.builtin.import_playbook: playbooks/play.yml +- ansible.builtin.import_playbook: playbooks/playbook-parent.yml diff --git a/src/ansiblelint/file_utils.py b/src/ansiblelint/file_utils.py index 6a6a5dd3e2..973de39b0e 100644 --- a/src/ansiblelint/file_utils.py +++ b/src/ansiblelint/file_utils.py @@ -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: diff --git a/test/test_file_utils.py b/test/test_file_utils.py index 6371eb296c..d86d2a19cb 100644 --- a/test/test_file_utils.py +++ b/test/test_file_utils.py @@ -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: