summaryrefslogtreecommitdiffstats
path: root/test/rules/fixtures/raw_task.py
blob: 6dfd7d9a2033694661319be18c0f41f589a47f80 (plain)
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
"""Test Rule that needs_raw_task."""

from __future__ import annotations

from typing import TYPE_CHECKING

from ansiblelint.rules import AnsibleLintRule

if TYPE_CHECKING:
    from ansiblelint.file_utils import Lintable
    from ansiblelint.utils import Task


class RawTaskRule(AnsibleLintRule):
    """Test rule that inspects the raw task."""

    id = "raw-task"
    shortdesc = "Test rule that inspects the raw task"
    tags = ["fake", "dummy", "test3"]
    needs_raw_task = True

    def matchtask(
        self,
        task: Task,
        file: Lintable | None = None,
    ) -> bool | str:
        """Match a task using __raw_task__ to inspect the module params type."""
        raw_task = task["__raw_task__"]
        module = task["action"]["__ansible_module_original__"]
        found_raw_task_params = not isinstance(raw_task[module], dict)
        return found_raw_task_params