summaryrefslogtreecommitdiffstats
path: root/src/ansiblelint/rules/deprecated_local_action.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:06:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:06:49 +0000
commit2fe34b6444502079dc0b84365ce82dbc92de308e (patch)
tree8fedcab52bbbc3db6c5aa909a88a7a7b81685018 /src/ansiblelint/rules/deprecated_local_action.py
parentInitial commit. (diff)
downloadansible-lint-2fe34b6444502079dc0b84365ce82dbc92de308e.tar.xz
ansible-lint-2fe34b6444502079dc0b84365ce82dbc92de308e.zip
Adding upstream version 6.17.2.upstream/6.17.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/ansiblelint/rules/deprecated_local_action.py')
-rw-r--r--src/ansiblelint/rules/deprecated_local_action.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/ansiblelint/rules/deprecated_local_action.py b/src/ansiblelint/rules/deprecated_local_action.py
new file mode 100644
index 0000000..fc3e4ff
--- /dev/null
+++ b/src/ansiblelint/rules/deprecated_local_action.py
@@ -0,0 +1,52 @@
+"""Implementation for deprecated-local-action rule."""
+# Copyright (c) 2016, Tsukinowa Inc. <info@tsukinowa.jp>
+# Copyright (c) 2018, Ansible Project
+from __future__ import annotations
+
+import sys
+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 TaskNoLocalAction(AnsibleLintRule):
+ """Do not use 'local_action', use 'delegate_to: localhost'."""
+
+ id = "deprecated-local-action"
+ description = "Do not use ``local_action``, use ``delegate_to: localhost``"
+ needs_raw_task = True
+ severity = "MEDIUM"
+ tags = ["deprecations"]
+ version_added = "v4.0.0"
+
+ def matchtask(
+ self,
+ task: Task,
+ file: Lintable | None = None,
+ ) -> bool | str:
+ """Return matches for a task."""
+ raw_task = task["__raw_task__"]
+ if "local_action" in raw_task:
+ return True
+
+ return False
+
+
+# testing code to be loaded only with pytest or when executed the rule file
+if "pytest" in sys.modules:
+ from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
+ from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports
+
+ def test_local_action(default_rules_collection: RulesCollection) -> None:
+ """Positive test deprecated_local_action."""
+ results = Runner(
+ "examples/playbooks/rule-deprecated-local-action-fail.yml",
+ rules=default_rules_collection,
+ ).run()
+
+ assert len(results) == 1
+ assert results[0].tag == "deprecated-local-action"