2

I want to convert Ansible string value to float and compare with another float value

In my ini file bin_version=6.5.17 I want to compare bin_version with 1 decimal value(6.5 >= 6.7) so I'm splitting it with 1 decimal value bin_version.split('.')[:2] and joining it with float "{{bin_version.split('.')[:2] | join('.')|float}}"

But it's not working as expected with when condition when: version >= 6.7, Does it float conversion(|float) really working here ?

tasks:
  - set_fact:
      version: "{{bin_version.split('.')[:2] | join('.')|float}}"

  - debug:
      msg: "{{version}}"
    when: version >= 6.7

task should be only executed when version >= 6.7

But

Case: 1: Pass

  when: version >= 6.7 // 6.5 >= 6.7

Expected result is task should be skipped but it's executing.

sanjayshr
  • 23
  • 1
  • 4

1 Answers1

3

You have to compare as below

when: bin_version is version('6.7', '>=')
Smily
  • 2,308
  • 2
  • 17
  • 41