# Using vars in comparison filters

**URL:** <https://forum.ansible.com/t/using-vars-in-comparison-filters/16472>\
**Category:** Ansible Project\
**Created:** [October 8, 2014, 6:42pm UTC](https://forum.ansible.com/t/using-vars-in-comparison-filters/16472 "2014-10-08T18:42:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mzp45](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@Mzp45](https://forum.ansible.com/u/Mzp45)\
**Post date:** [October 8, 2014, 6:42pm UTC](https://forum.ansible.com/t/using-vars-in-comparison-filters/16472/1 "2014-10-08T18:42:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [October 8, 2014, 6:45pm UTC](https://forum.ansible.com/t/using-vars-in-comparison-filters/16472/2 "2014-10-08T18:45:23Z")

</div>

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,'\<') }}"

---

<div class="post-metadata">

**Author:** ![Mzp45](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@Mzp45](https://forum.ansible.com/u/Mzp45)\
**Post date:** [October 8, 2014, 7:46pm UTC](https://forum.ansible.com/t/using-vars-in-comparison-filters/16472/3 "2014-10-08T19:46:11Z")

</div>

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

Thanks for your help
