summaryrefslogtreecommitdiffstats
path: root/src/ansiblelint/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ansiblelint/config.py')
-rw-r--r--src/ansiblelint/config.py69
1 files changed, 51 insertions, 18 deletions
diff --git a/src/ansiblelint/config.py b/src/ansiblelint/config.py
index 6164b10..ee9dea0 100644
--- a/src/ansiblelint/config.py
+++ b/src/ansiblelint/config.py
@@ -1,4 +1,5 @@
"""Store configuration options as a singleton."""
+
from __future__ import annotations
import json
@@ -67,7 +68,7 @@ DEFAULT_KINDS = [
{"requirements": "**/requirements.{yaml,yml}"}, # v2 and v1
{"playbook": "**/molecule/*/*.{yaml,yml}"}, # molecule playbooks
{"yaml": "**/{.ansible-lint,.yamllint}"},
- {"changelog": "**/changelogs/changelog.yaml"},
+ {"changelog": "**/changelogs/changelog.{yaml,yml}"},
{"yaml": "**/*.{yaml,yml}"},
{"yaml": "**/.*.{yaml,yml}"},
{"sanity-ignore-file": "**/tests/sanity/ignore-*.txt"},
@@ -98,22 +99,41 @@ BASE_KINDS = [
{"text/python": "**/*.py"},
]
+# File kinds that are recognized by ansible, used internally to force use of
+# YAML 1.1 instead of 1.2 due to ansible-core dependency on pyyaml.
+ANSIBLE_OWNED_KINDS = {
+ "handlers",
+ "galaxy",
+ "meta",
+ "meta-runtime",
+ "playbook",
+ "requirements",
+ "role-arg-spec",
+ "rulebook",
+ "tasks",
+ "vars",
+}
+
PROFILES = yaml_from_file(Path(__file__).parent / "data" / "profiles.yml")
LOOP_VAR_PREFIX = "^(__|{role}_)"
@dataclass
-class Options: # pylint: disable=too-many-instance-attributes,too-few-public-methods
+class Options: # pylint: disable=too-many-instance-attributes
"""Store ansible-lint effective configuration options."""
+ # Private attributes
+ _skip_ansible_syntax_check: bool = False
+
+ # Public attributes
cache_dir: Path | None = None
colored: bool = True
configured: bool = False
- cwd: Path = Path(".")
+ cwd: Path = Path()
display_relative_path: bool = True
exclude_paths: list[str] = field(default_factory=list)
- format: str = "brief" # noqa: A003
+ format: str = "brief"
lintables: list[str] = field(default_factory=list)
list_rules: bool = False
list_tags: bool = False
@@ -152,6 +172,27 @@ class Options: # pylint: disable=too-many-instance-attributes,too-few-public-me
version: bool = False # display version command
list_profiles: bool = False # display profiles command
ignore_file: Path | None = None
+ max_tasks: int = 100
+ max_block_depth: int = 20
+ # Refer to https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix
+ _default_supported = ["2.15.", "2.16.", "2.17."]
+ supported_ansible_also: list[str] = field(default_factory=list)
+
+ @property
+ def nodeps(self) -> bool:
+ """Returns value of nodeps feature."""
+ # We do not want this to be cached as it would affect our testings.
+ return bool(int(os.environ.get("ANSIBLE_LINT_NODEPS", "0")))
+
+ def __post_init__(self) -> None:
+ """Extra initialization logic."""
+ if self.nodeps:
+ self.offline = True
+
+ @property
+ def supported_ansible(self) -> list[str]:
+ """Returns list of ansible versions that are considered supported."""
+ return sorted([*self._default_supported, *self.supported_ansible_also])
options = Options()
@@ -166,15 +207,6 @@ collection_list: list[str] = []
log_entries: list[tuple[int, str]] = []
-def get_rule_config(rule_id: str) -> dict[str, Any]:
- """Get configurations for the rule ``rule_id``."""
- rule_config = options.rules.get(rule_id, {})
- if not isinstance(rule_config, dict): # pragma: no branch
- msg = f"Invalid rule config for {rule_id}: {rule_config}"
- raise RuntimeError(msg)
- return rule_config
-
-
@lru_cache
def ansible_collections_path() -> str:
"""Return collection path variable for current version of Ansible."""
@@ -241,7 +273,6 @@ def guess_install_method() -> str:
else:
logging.debug("Skipping %s as it is not installed.", package_name)
use_pip = False
- # pylint: disable=broad-except
except (AttributeError, ModuleNotFoundError) as exc:
# On Fedora 36, we got a AttributeError exception from pip that we want to avoid
# On NixOS, we got a ModuleNotFoundError exception from pip that we want to avoid
@@ -269,6 +300,11 @@ def get_version_warning() -> str:
# 0.1dev1 is special fallback version
if __version__ == "0.1.dev1": # pragma: no cover
return ""
+ pip = guess_install_method()
+ # If we do not know how to upgrade, we do not want to show any warnings
+ # about version.
+ if not pip:
+ return ""
msg = ""
data = {}
@@ -309,9 +345,6 @@ def get_version_warning() -> str:
msg = "[dim]You are using a pre-release version of ansible-lint.[/]"
elif current_version < new_version:
msg = f"""[warning]A new release of ansible-lint is available: [red]{current_version}[/] → [green][link={html_url}]{new_version}[/][/][/]"""
-
- pip = guess_install_method()
- if pip:
- msg += f" Upgrade by running: [info]{pip}[/]"
+ msg += f" Upgrade by running: [info]{pip}[/]"
return msg