Open etdsoft opened 9 years ago
In addition, since rbenv_gem
uses the ruby_gem
provider (Chef::Provider::Package::Rubygems
) it is broken in the last versions of Chef:
* rbenv_gem[rake] action install
================================================================================
Error executing action `install` on resource 'rbenv_gem[rake]'
================================================================================
ArgumentError
-------------
Gem options must be passed to gem_package as a string instead of a hash when
using this installation of Chef because it runs with its own packaged Ruby. A hash
may only be used when installing a gem to the same Ruby installation that Chef is
running under. See https://docs.chef.io/resource_gem_package.html for more information.
Error raised at rbenv_gem[rake] from /tmp/kitchen/cache/cookbooks/mycookbook/recipes/packages.rb:46:in `from_file'
Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/rbenv/libraries/provider_rbenv_rubygems.rb:64:in `initialize'
/tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:78:in `run_action'
/tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block (2 levels) in converge'
/tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `each'
/tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block in converge'
/tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:105:in `converge'
Resource Declaration:
---------------------
# In /tmp/kitchen/cache/cookbooks/mycookbook/recipes/packages.rb
46: rbenv_gem 'rake' do
47: options '--force' => nil
48: ruby_version '2.2.4'
49: end
Compiled Resource:
------------------
# Declared in /tmp/kitchen/cache/cookbooks/mycookbook/recipes/packages.rb:46:in `from_file'
rbenv_gem("rake") do
provider Chef::Provider::Package::RbenvRubygems
action :install
retries 0
retry_delay 2
default_guard_interpreter :default
declared_type :rbenv_gem
cookbook_name "mycookbook"
recipe_name "packages"
ruby_version "2.2.4"
options {"--force"=>nil}
package_name "rake"
end
Platform:
---------
x86_64-linux
In the master branch the :options are defined as either a Hash or a String which is good
https://github.com/RiotGames/rbenv-cookbook/blob/master/resources/gem.rb#L30
But then they are always casted into a String for passing to the
gem install
command:https://github.com/RiotGames/rbenv-cookbook/blob/master/libraries/provider_rbenv_rubygems.rb#L88
This means that if we need to pass an extra environment variable to the shell, there is no way to do so. So instead of being able to run:
I had to replace the
rbenv_gem
block with abash
block:Would it make sense to detect the type of the :options parameter inside :install_via_gem_command and if it's a string, pass it as an argument, and if it's a hash, merge it with the hash you're passing to :shell_out!?