Reputation: 2452
I use Ansible 2.8.5. I could use ansible_facts.package
but simple, let's use the following playbook.
- debug:
msg: "{{ { 'version':'5.52.2' } is version('6.0.0','>=') }}"
returns
..."msg" : True
How can I get a correct dot separated version correctly compared?
I read the official documentation and did not manage to understand how the function version
is working. Some people even said that this should rise a TypeError
exception. Nobody seems to understand how version
is designed to work...
Upvotes: 0
Views: 1243
Reputation: 456
Try this. refer Version Comparison. Provide the version in the string.
- hosts: localhost
tasks:
- set_fact:
version1: "5.52.2"
version2: "6.0.0"
- debug:
msg: "{{ version1 is version( version2 , '>=') }}"
Upvotes: 1
Reputation: 2000
Why don't you register
the version first in a variable and then add a check. Then you can compare the content of the variable. Here is an example -
failed_when: "'<version>{{ version }}</version>' not in this.content"
- debug: msg=" version is {{ this.content.split('\n')[0].split('version')[1].split('>')[1].split('</')[0]}}"
Upvotes: 0