There are two useful Jinja filters that could help dealing with version numbers in Ansible code. One is version_compare, which allows to compare version numbers. The other is regex_replace, which can be used to get a major.minor version number from a longer version number.
Version comparison
It