# version\_compare filter in template

**URL:** <https://forum.ansible.com/t/version-compare-filter-in-template/22194>\
**Category:** Ansible Project\
**Created:** [August 2, 2016, 7:54pm UTC](https://forum.ansible.com/t/version-compare-filter-in-template/22194 "2016-08-02T19:54:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtovey](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mtovey](https://forum.ansible.com/u/mtovey)\
**Post date:** [August 2, 2016, 7:54pm UTC](https://forum.ansible.com/t/version-compare-filter-in-template/22194/1 "2016-08-02T19:54:40Z")

</div>

I want to make a decision in a template using the version\_compare filter:

{% if httpd\_version|version\_compare(‘2.4’, ‘\>=’) %}

This fails with the message “{‘msg’: “TypeError: ‘in ’ requires string as left operand”, ‘failed’: True}”.

The variable ‘httpd\_version’ contains the installed version of Apache on the host. I derived that by using a shell task in the playbook to extract the version and then using set\_fact to store it. What is the proper method of testing the version in a template?

---

<div class="post-metadata">

**Author:** ![mtovey](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mtovey](https://forum.ansible.com/u/mtovey)\
**Post date:** [August 2, 2016, 8:36pm UTC](https://forum.ansible.com/t/version-compare-filter-in-template/22194/2 "2016-08-02T20:36:44Z")

</div>

Okay, I don’t know what it was, but the filter as written below does work. Something else in the template was munged. I got it working by starting over with my original template before I tried to use the version compare filter and then adding the filter back in. This time it worked perfectly. Of course, I didn’t bother to save the munged template before starting over, so I can’t compare the munged template with the working template. What ever. It is working, That is all I wanted.
