File: test_skip_import_playbook.py

package info (click to toggle)
ansible-lint 25.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,660 kB
  • sloc: python: 19,201; sh: 70; makefile: 7
file content (42 lines) | stat: -rw-r--r-- 1,059 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Test related to skipping import_playbook."""

from pathlib import Path

from ansiblelint.rules import RulesCollection
from ansiblelint.runner import Runner

IMPORTED_PLAYBOOK = """\
---
- name: Fixture
  hosts: all
  tasks:
    - name: Success # noqa: no-free-form
      ansible.builtin.fail: msg="fail"
      when: false
"""

MAIN_PLAYBOOK = """\
---
- name: Fixture
  hosts: all

  tasks:
    - name: Should be shell  # noqa: command-instead-of-shell no-changed-when no-free-form
      ansible.builtin.shell: echo lol

- name: Should not be imported
  import_playbook: imported_playbook.yml
"""


def test_skip_import_playbook(
    default_rules_collection: RulesCollection, tmp_path: Path
) -> None:
    """Verify that a playbook import is skipped after a failure."""
    playbook_path = tmp_path / "playbook.yml"
    playbook_path.write_text(MAIN_PLAYBOOK)
    (tmp_path / "imported_playbook.yml").write_text(IMPORTED_PLAYBOOK)

    runner = Runner(playbook_path, rules=default_rules_collection)
    results = runner.run()
    assert len(results) == 0