2

I need to dynamically install apt packages when the full Ubuntu version (Major.Minor like 18.10) is larger or smaller than a specified value. This is required to install the corrent libvirt-bin package, that were renamed in 18.10. The fact ansible_distribution_version holds the numeric version and I found the version comparision filter in an old Ansible doc, that seems renamed in Ansible 2.5 but it doesn't work in the latest 2.9 release:

- name: Execute on ubuntu 18.10 or newer
  shell: "echo Youre on Ubuntu 18.10 or newer"
  when: ansible_distribution_version | version('18.10', '>=')

The conditional check 'ansible_distribution_version | version('19.10', '>=')' failed. The error was: template error while templating string: no filter named 'version'.

The latest (currently 2.9) documentation doesn't contain any filter for version comparisation. I tried float-conversation, which seems to work:

- name: Execute on ubuntu 18.10 or newer
  shell: "echo executed on ubuntu 18.10 or newer"
  when: ansible_distribution_version | float >= 18.10

Are there any disadvantages of using this conversation that justifys why version_comparisation and version filters were introduced? Or is there another filter to safely compare versions that I haven't found?

Lion
  • 16,606
  • 23
  • 86
  • 148
  • 1
    Instead of using | , can you try as ansible_distribution_version is version('18.10', '>=') – Smily Dec 10 '19 at 10:19

1 Answers1

7

Using tests as filters is deprecated. Instead of using result|version use result is version (as advised in the documentation)

when: ansible_distribution_version is version('18.10', '>=')
Zeitounator
  • 38,476
  • 7
  • 53
  • 66
Smily
  • 2,308
  • 2
  • 17
  • 41