diff --git a/src/ansiblelint/cli.py b/src/ansiblelint/cli.py index 9e6ec582f8..8d457950a6 100644 --- a/src/ansiblelint/cli.py +++ b/src/ansiblelint/cli.py @@ -499,6 +499,7 @@ def merge_config(file_config: dict[Any, Any], cli_config: Options) -> Options: "enable_list": [], "only_builtins_allow_collections": [], "only_builtins_allow_modules": [], + "add_supported_ansible": [], # do not include "write_list" here. See special logic below. } diff --git a/src/ansiblelint/config.py b/src/ansiblelint/config.py index c79e31e07b..d631764da3 100644 --- a/src/ansiblelint/config.py +++ b/src/ansiblelint/config.py @@ -174,6 +174,7 @@ class Options: # pylint: disable=too-many-instance-attributes ignore_file: Path | None = None max_tasks: int = 100 max_block_depth: int = 20 + add_supported_ansible: list[str] = field(default_factory=list) @property def nodeps(self) -> bool: diff --git a/src/ansiblelint/rules/meta_runtime.py b/src/ansiblelint/rules/meta_runtime.py index be0e6985e1..fdbcf0cdeb 100644 --- a/src/ansiblelint/rules/meta_runtime.py +++ b/src/ansiblelint/rules/meta_runtime.py @@ -30,10 +30,9 @@ class CheckRequiresAnsibleVersion(AnsibleLintRule): tags = ["metadata"] version_added = "v6.11.0 (last update)" - # Refer to https://access.redhat.com/support/policy/updates/ansible-automation-platform - # Also add devel to this list - supported_ansible = ["2.15.", "2.16.", "2.17."] - supported_ansible_examples = [f">={x}0" for x in supported_ansible] + # 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."] # Move to constants.py? + supported_ansible_examples = [f">={x}0" for x in default_supported] _ids = { "meta-runtime[unsupported-version]": f"'requires_ansible' key must refer to a currently supported version such as: {', '.join(supported_ansible_examples)}", "meta-runtime[invalid-version]": "'requires_ansible' is not a valid requirement specification", @@ -50,11 +49,16 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: if file.kind != "meta-runtime": return [] - version_required = file.data.get("requires_ansible", None) + if self._collection.options.add_supported_ansible: + self.default_supported.extend( + self._collection.options.add_supported_ansible + ) - if version_required: + requires_ansible = file.data.get("requires_ansible", None) + + if requires_ansible: if not any( - version in version_required for version in self.supported_ansible + version in requires_ansible for version in self.default_supported ): results.append( self.create_matcherror( @@ -65,7 +69,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: ) try: - SpecifierSet(version_required) + SpecifierSet(requires_ansible) except ValueError: results.append( self.create_matcherror(