ansible-lint icon indicating copy to clipboard operation
ansible-lint copied to clipboard

feature: detect incorrect use of version comparison

Open ssbarnea opened this issue 4 years ago • 1 comments

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/

ssbarnea avatar Oct 12 '19 08:10 ssbarnea

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.

bluikko avatar Jan 02 '22 07:01 bluikko

Closing as we do not currently plan to work on implementing it. Still, if someone else makes a pull-request, we will review it.

ssbarnea avatar Mar 07 '23 15:03 ssbarnea