I’m writing a couple of thor jobs to configure a workstation for Chef
development. One of the things I want to do is to install a few gems into
the chefdk installed on the system if they don’t exist. I thought it would
be simple enough to just shell out and run the chef command to install
these gems (i.e.
chef gem install kitchen-ec2 but calling the chef
command, or indeed the ChefDK ruby from within my bundle results in an
error stating that a gem can’t be found.
So if I run bin/thor myorg:check (where bin/thor is a binstub in my
bundle) and in the thor jobs there’s any command that calls the chef
chef -v *then I get the following:
block in materialize': Could not find rake-10.4.2 in any of the sources (Bundler::GemNotFound) from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.3/lib/bundler/spec_set.rb:85:inmap!'
materialize' from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.3/lib/bundler/definition.rb:139:inspecs’
specs_for' from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.3/lib/bundler/definition.rb:173:inrequested_specs’
requested_specs' from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.3/lib/bundler/runtime.rb:13:insetup’
setup' from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.3/lib/bundler/setup.rb:18:in<top (required)>‘
require' from /opt/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:inrequire’
or *system(‘chef -v’) *then I get the following error:
Could not find rake-10.4.2 in any of the sources
bundle install to install missing gems.
My bundle has that rake gem but for ruby v2.0.x instead of v2.1.x which the
chefdk uses. I’m guessing that running from within a bundle is messing up
the bundle environment that the chef executable uses, but I’ve not the
knowlege of how this works to get it working.
Is there any way around this (other than use thor from the system ruby,
which would be the fallback, but not ideal)? Will dropping certain
environment variables related to bundler when shelling out fix the problem?
Mobile: +1 778 952 2025