Skip to content

Commit

Permalink
Correct requires_ansible error message
Browse files Browse the repository at this point in the history
Related: #3950
  • Loading branch information
ssbarnea committed Dec 20, 2023
1 parent 185ec05 commit 8411a2d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"evenBetterToml.formatter.alignComments": false,
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
}
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
}
}
}
15 changes: 4 additions & 11 deletions src/ansiblelint/rules/meta_runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@

This rule checks the meta/runtime.yml `requires_ansible` key against the list of currently supported versions of ansible-core.

This rule can produce messages such:

- `requires_ansible` key must be set to a supported version.

Currently supported versions of ansible-core are:

- `2.13.x`
- `2.14.x`
- `2.15.x`

This rule can produce messages such as:

- `meta-runtime[unsupported-version]` - `requires_ansible` key must contain a supported version - 2.13.x, 2.14.x, 2.15.x.
- `meta-runtime[unsupported-version]` - `requires_ansible` key must refer to a currently supported version such: >=2.14.0, >=2.15.0, >=2.16.0
- `meta-runtime[invalid-version]` - `requires_ansible` is not a valid requirement specification

Please note that the linter will allow only a full version of Ansible such `2.16.0` and not allow their short form, like `2.16`. This is a safety measure
for asking authors to mention an explicit version that they tested with. Over the years we spotted multiple problems caused by the use of the short versions, users
ended up trying an outdated version that was never tested against by the collection maintainer.

## Problematic code

Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/meta_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class CheckRequiresAnsibleVersion(AnsibleLintRule):
# Refer to https://access.redhat.com/support/policy/updates/ansible-automation-platform
# Also add devel to this list
supported_ansible = ["2.14.", "2.15.", "2.16."]
supported_ansible_examples = [f">={x}0" for x in supported_ansible]
_ids = {
"meta-runtime[unsupported-version]": "'requires_ansible' key must be set to a supported version - 2.13.x, 2.14.x, 2.15.x",
"meta-runtime[unsupported-version]": f"'requires_ansible' key must refer to a currently supported version such: {', '.join(supported_ansible_examples)}",
"meta-runtime[invalid-version]": "'requires_ansible' is not a valid requirement specification",
}

Expand All @@ -56,7 +57,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
):
results.append(
self.create_matcherror(
message="requires_ansible key must be set to a supported version.",
message=self._ids["meta-runtime[unsupported-version]"],
tag="meta-runtime[unsupported-version]",
filename=file,
),
Expand Down

0 comments on commit 8411a2d

Please sign in to comment.