| Forum

How to compare versions in Ansible

I need to execute few tasks in Ansible only when the application version is greater than 3.1.0. Is there any built-in module in Anisble to compare version patterns like x.x.x?

There a version test available in Ansible.
You can use it like this

  app_version: 3.0.0
  - name: Upgrade application
    shell: "./"
    when: app_version is version('3.1.0', '<')

Note that here, the app_version variable is not inside a {{ }} when using the version test.