Using vars in comparison filters

1,682 views
Skip to first unread message

Mzp45

unread,
Oct 8, 2014, 2:42:45 PM10/8/14
to ansible...@googlegroups.com
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 

Michael Peters

unread,
Oct 8, 2014, 2:45:26 PM10/8/14
to ansible...@googlegroups.com
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,'<') }}"
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/76886694-39f3-4504-8fe3-2d53e68d8e2c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Mzp45

unread,
Oct 8, 2014, 3:46:11 PM10/8/14
to ansible...@googlegroups.com
Hi Michael,
That was the problem:) I made the change and it works as expected

Thanks for your help
Reply all
Reply to author
Forward
0 new messages