Skip to content

Commit

Permalink
Adding logic for configuring supported ansible versions
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonlhart committed Jun 4, 2024
1 parent 17c812e commit f99fb4a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/ansiblelint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Expand Down
1 change: 1 addition & 0 deletions src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 12 additions & 8 deletions src/ansiblelint/rules/meta_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit f99fb4a

Please sign in to comment.