summaryrefslogtreecommitdiffstats
path: root/src/ansiblelint/rules/args.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ansiblelint/rules/args.py27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/ansiblelint/rules/args.py b/src/ansiblelint/rules/args.py
index 2acf32e..fb9f991 100644
--- a/src/ansiblelint/rules/args.py
+++ b/src/ansiblelint/rules/args.py
@@ -1,4 +1,5 @@
"""Rule definition to validate task options."""
+
from __future__ import annotations
import contextlib
@@ -8,7 +9,6 @@ import json
import logging
import re
import sys
-from functools import lru_cache
from typing import TYPE_CHECKING, Any
# pylint: disable=preferred-module
@@ -18,11 +18,11 @@ from unittest.mock import patch
# pylint: disable=reimported
import ansible.module_utils.basic as mock_ansible_module
from ansible.module_utils import basic
-from ansible.plugins.loader import PluginLoadContext, module_loader
from ansiblelint.constants import LINE_NUMBER_KEY
from ansiblelint.rules import AnsibleLintRule, RulesCollection
from ansiblelint.text import has_jinja
+from ansiblelint.utils import load_plugin
from ansiblelint.yaml_utils import clean_json
if TYPE_CHECKING:
@@ -66,12 +66,6 @@ workarounds_inject_map = {
}
-@lru_cache
-def load_module(module_name: str) -> PluginLoadContext:
- """Load plugin from module name and cache it."""
- return module_loader.find_plugin_with_context(module_name)
-
-
class ValidationPassedError(Exception):
"""Exception to be raised when validation passes."""
@@ -103,7 +97,7 @@ class ArgsRule(AnsibleLintRule):
task: Task,
file: Lintable | None = None,
) -> list[MatchError]:
- # pylint: disable=too-many-locals,too-many-return-statements
+ # pylint: disable=too-many-return-statements
results: list[MatchError] = []
module_name = task["action"]["__ansible_module_original__"]
failed_msg = None
@@ -111,7 +105,7 @@ class ArgsRule(AnsibleLintRule):
if module_name in self.module_aliases:
return []
- loaded_module = load_module(module_name)
+ loaded_module = load_plugin(module_name)
# https://github.com/ansible/ansible-lint/issues/3200
# since "ps1" modules cannot be executed on POSIX platforms, we will
@@ -150,14 +144,10 @@ class ArgsRule(AnsibleLintRule):
CustomAnsibleModule,
):
spec = importlib.util.spec_from_file_location(
- name=loaded_module.resolved_fqcn,
+ name=loaded_module.plugin_resolved_name,
location=loaded_module.plugin_resolved_path,
)
- if spec:
- assert spec.loader is not None
- module = importlib.util.module_from_spec(spec)
- spec.loader.exec_module(module)
- else:
+ if not spec:
assert file is not None
_logger.warning(
"Unable to load module %s at %s:%s for options validation",
@@ -166,6 +156,9 @@ class ArgsRule(AnsibleLintRule):
task[LINE_NUMBER_KEY],
)
return []
+ assert spec.loader is not None
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
try:
if not hasattr(module, "main"):
@@ -196,9 +189,9 @@ class ArgsRule(AnsibleLintRule):
)
sanitized_results = self._sanitize_results(results, module_name)
- return sanitized_results
except ValidationPassedError:
return []
+ return sanitized_results
# pylint: disable=unused-argument
def _sanitize_results(