Reputation: 7394
I'm trying to capture the main version number of a variable, and to do this I'm trying to remove the numbers after the main version number:
In variable.yml
:
version: 3.9.5
main_version: "{{ version | regex_replace('^.*(..)$', '')}}"
This should give me 3.9
, however debug gives me nothing.
What's the correct way of doing this?
(And making sure that it would still be able to handle things such as 3.10.1
, so that would return a main_version
of 3.10
, and also things such as 3.10.1-rcblah
, and that would return a main_version
of 3.10
)
Upvotes: 1
Views: 16847
Reputation: 4738
I guess your regexp should be something like:
'^.*(\.[0-9]*)$'
But why don't you use version_compare
? http://docs.ansible.com/ansible/latest/playbooks_tests.html#version-comparison
Upvotes: 2