Using vars in comparison filters

Hi,
I’m trying to compare 2 versions of firmware using the version_compare filter. When i use a variable like this it seems like it doesn’t evaluate the function correctly

debug: msg=“Firmware needs to be updated”
when: “{{ firmware_version_on_server.stdout | version_compare(‘{{ firmware_version_desired }}’,‘<’) }}”

However when i specify the actual version version it works
when: “{{ firmware_version_on_server.stdout | version_compare(‘2.31.5050’,‘<’) }}”

I added the strict=True syntax in the first case and i get the following error
when: “{{ firmware_version_on_server.stdout | version_compare(‘{{ firmware_version_desired }}’,‘<’,strict=True) }}”

fatal: [xxxxxxx] => Version comparison: invalid version number ‘{{firmware_version_desired}}’

Does the version_compare function not accept variables or is there some kind of string to integer conversion involved?

firmware_version_on_server.stdout is a registered variable obtained from a shell command

  • name: Get firmware version of card
    shell: “ethtool -i eth4 | grep firmware-version | awk ‘{print $NF}’”
    register: firmware_version_on_server

Thanks

It seems you're trying to "double template". If you're inside of the
{{ }} markers you don't need further {{ }} templating. Trying
something like this:

debug: msg="Firmware needs to be updated"
when: "{{ firmware_version_on_server.stdout |
version_compare(firmware_version_desired,'<') }}"

Hi Michael,
That was the problem:) I made the change and it works as expected

Thanks for your help