ansible-lint
ansible-lint copied to clipboard
feature: detect incorrect use of version comparison
Issue Type
- Feature request
It would prove very useful if ansible-lint could identify what appears to be incorrect use of comparision operators on variables that contain versions.
Example:
# bad
{% if ansible_distribution_version > 9 %}
# good
{% if ansible_distribution_version is version('9.0', '>=') %}
I am aware that we may need whitelist (pattern?) for matching such variables but even if we only include some hardcoded list it would help lots of users as this is a very common error.
Reference: https://strugglers.net/~andy/blog/2019/03/28/comparing-versions-in-ansible-templates/
Since many -- or most? but not all? -- facts that are numbers are actually string
type and not int
, maybe all numeric comparisons of facts without forcing a type such as int
/float
should be detected.
Closing as we do not currently plan to work on implementing it. Still, if someone else makes a pull-request, we will review it.