Test plugin version error : could not compare 'str' and 'int'

Hi,

Here is an abstract of my role:

- name: Get Git's version
  ansible.builtin.shell: "git --version | awk -F' ' { print $3 }'"
  register: base_git_installed_version
  when: base_git_installed.rc == 0
- name: Debug Git version
  ansible.builtin.debug:
    var: base_git_installed_version
- name: Assert Git version
  ansible.builtin.assert:
    that: "{{ base_git_installed_version|trim is version('1.7.1', 'gt') }}"
    fail_msg: "Git version is not enought for ansible git plugin"

I’ve the following error message:

FAILED! => {“changed”: false, “msg”: “Task failed: The test plugin ‘ansible.builtin.version’ failed: Version comparison failed: ‘<’ not supported between instances of ‘str’ and ‘int’”}

I’ve tried many combinations : float filter on both arg inputs, str or int filters, with and without double quotes around the expression, single quotes around inputs. Nothing…

Thx for your help!

Welcome to The Forum, @fghebert!

This part isn’t working. base_git_installed doesn’t exist. (Missing prior task?)

But beside that, you need to look at the base_git_installed_version.stdout or base_git_installed_version.stdout_lines[0] to get the datum you want.

- name: Assert Git version
  ansible.builtin.assert:
    that: "{{ base_git_installed_version.stdout_lines[0] is version('1.7.1', 'gt') }}"
    fail_msg: "Git version is not enought for ansible git plugin"

produces

TASK [Debug Git version] *************************
task path: /home/utoddl/ansible/fghebert_00.yml:12
ok: [localhost] => 
  base_git_installed_version:
    changed: true
    cmd: git --version | awk -F' ' '{ print $3 }'
    delta: '0:00:00.004688'
    end: '2026-01-23 09:00:14.357694'
    failed: false
    msg: ''
    rc: 0
    start: '2026-01-23 09:00:14.353006'
    stderr: ''
    stderr_lines: []
    stdout: 2.52.0
    stdout_lines:
    - 2.52.0

TASK [Assert Git version] ************************
task path: /home/utoddl/ansible/fghebert_00.yml:16
ok: [localhost] => changed=false 
  msg: All assertions passed
2 Likes

Hi again,

many many thanks for you so quick reply! Getting the stdout_lines property works! Wow! Thanks again!