sethvargo/chef-sugar — pull request #54 by schisamo (2014-08-08 16:48:26+00:00)
Title: Don’t raise exception if `version_for` fails

In some cases a version check command will exit with a non-zero status. An example of this would be a version check on a utility that is not yet installed. Take for example the following Chef recipe code:

```ruby
ruby_version = '1.8.7-p374'

remote_install "ruby-#{ruby_version}-rubygems" do
source 'http://production.cf.rubygems.org/rubygems/rubygems-2.2.2.tgz'
version '2.2.2'
checksum '572dd13baa1dfb9756db9fbfeb629be1634efddb7014c552845c0e9a5a643009'
install_command "chruby-exec #{ruby_version} -- ruby setup.rb"
not_if { installed_at_version?('chruby-exec', '2.2.2', "#{ruby_version} -- gem --version") }
end
```

which produces a Chef run failure like this:

```
Recipe: opscode-ci::_ruby
* ruby_install[1.8.7-p374] action installRecipe:
* execute[install ruby-1.8.7-p374] action run
- execute ruby-install --jobs=8 ruby 1.8.7-p374 -- --disable-install-rdoc --disable-install-ri --with-out-ext=tcl --with-out-ext=tk --without-tcl --without-tk

- install ruby_install[1.8.7-p374]

Recipe: opscode-ci::_ruby
* remote_install[ruby-1.8.7-p374-rubygems] action install
================================================================================
Error executing action `install` on resource 'remote_install[ruby-1.8.7-p374-rubygems]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '127'
---- Begin output of chruby-exec 1.8.7-p374 -- gem --version ----
STDOUT:
STDERR: stdin: is not a tty
bash: gem: command not found
---- End output of chruby-exec 1.8.7-p374 -- gem --version ----
Ran chruby-exec 1.8.7-p374 -- gem --version returned 127

Cookbook Trace:
---------------
/var/chef/cache/cookbooks/opscode-ci/recipes/_ruby.rb:50:in `block (3 levels) in from_file'

Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/opscode-ci/recipes/_ruby.rb

45: remote_install "ruby-#{ruby_version}-rubygems" do
46: source 'http://production.cf.rubygems.org/rubygems/rubygems-2.2.2.tgz'
47: version '2.2.2'
48: checksum '572dd13baa1dfb9756db9fbfeb629be1634efddb7014c552845c0e9a5a643009'
49: install_command "chruby-exec #{ruby_version} -- ruby setup.rb"
50: not_if { installed_at_version?('chruby-exec', '2.2.2', "#{ruby_version} -- gem --version") }
51: end
52:

Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/opscode-ci/recipes/_ruby.rb:45:in `block in from_file'

remote_install("ruby-1.8.7-p374-rubygems") do
action :install
retries 0
retry_delay 2
guard_interpreter :default
cookbook_name "opscode-ci"
recipe_name "_ruby"
source "http://production.cf.rubygems.org/rubygems/rubygems-2.2.2.tgz"
version "2.2.2"
checksum "572dd13baa1dfb9756db9fbfeb629be1634efddb7014c552845c0e9a5a643009"
install_command "chruby-exec 1.8.7-p374 -- ruby setup.rb"
not_if { #code block }
end

Running handlers:
[2014-08-08T16:40:24+00:00] ERROR: Running exception handlers
Running handlers complete

[2014-08-08T16:40:24+00:00] ERROR: Exception handlers complete
[2014-08-08T16:40:24+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 179 resources updated in 660.480161413 seconds
[2014-08-08T16:40:25+00:00] ERROR: remote_install[ruby-1.8.7-p374-rubygems] (opscode-ci::_ruby line 45) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '127'
---- Begin output of chruby-exec 1.8.7-p374 -- gem --version ----
STDOUT:
STDERR: stdin: is not a tty
bash: gem: command not found
---- End output of chruby-exec 1.8.7-p374 -- gem --version ----
Ran chruby-exec 1.8.7-p374 -- gem --version returned 127
[2014-08-08T16:40:25+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
```