Check package version

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

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”

try this:

   - name: Verify ruby version is 1.9
     shell: /opt/vagrant_ruby/bin/ruby --version |awk '{print $2}'
     register: status

   - fail: "This is bad version"
     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.