Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct requires_ansible error message #3954

Merged
merged 4 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 as: >=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 as: {', '.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