Check package version

514 views
Skip to first unread message

MIkeJ

unread,
Nov 20, 2015, 2:51:57 PM11/20/15
to Ansible Project

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

MIkeJ

unread,
Nov 20, 2015, 3:56:15 PM11/20/15
to Ansible Project
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"

Brian Coca

unread,
Nov 20, 2015, 8:19:41 PM11/20/15
to Ansible Project
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.
--
Brian Coca
Reply all
Reply to author
Forward
0 new messages