# Check package version

**URL:** <https://forum.ansible.com/t/check-package-version/19818>\
**Category:** Ansible Project\
**Created:** [November 20, 2015, 5:36pm UTC](https://forum.ansible.com/t/check-package-version/19818 "2015-11-20T17:36:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MIkeJ](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@MIkeJ](https://forum.ansible.com/u/MIkeJ)\
**Post date:** [November 20, 2015, 5:36pm UTC](https://forum.ansible.com/t/check-package-version/19818/1 "2015-11-20T17:36:38Z")

</div>

Hello,

I want to run a check in my playbook for the current version of ruby package installed and if its not the version Im expecting then fail the play.

How can I go about doing this?

Thanks

Mike

---

<div class="post-metadata">

**Author:** ![MIkeJ](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@MIkeJ](https://forum.ansible.com/u/MIkeJ)\
**Post date:** [November 20, 2015, 8:56pm UTC](https://forum.ansible.com/t/check-package-version/19818/2 "2015-11-20T20:56:15Z")

</div>

An example of what I think might work.

- name: Verify ruby version is 1.9

shell: echo /opt/vagrant\_ruby/bin/ruby --version

register: status

- fail: “This is bad version”

when: var=status.stdout\_lines != “1.9”

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 21, 2015, 1:19am UTC](https://forum.ansible.com/t/check-package-version/19818/3 "2015-11-21T01:19:36Z")

</div>

try this:

&nbsp;&nbsp;&nbsp;- name: Verify ruby version is 1.9  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: /opt/vagrant\_ruby/bin/ruby --version |awk '{print $2}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: status

&nbsp;&nbsp;&nbsp;- fail: "This is bad version"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: status.stdout|version\_compare("1.9", "eq")

`echo` is not needed as `ruby --version` already prints to screen, but  
you really only want the version number which is what awk is doing  
i use version\_compare filter as it will match 1.9.x minor versions  
also, if you don't want this add a ,strict=true to the filter to make  
sure it is purely 1.9.
