Skip to content

Instantly share code, notes, and snippets.

@dergachev
Last active December 26, 2015 04:19
Show Gist options
  • Save dergachev/7092697 to your computer and use it in GitHub Desktop.
Save dergachev/7092697 to your computer and use it in GitHub Desktop.

I have found that when running gem_package 'bundler' from within a chef run started by gusteau, the gem is installed into the chef-omnnibus embedded environment instead of the system ruby environment. (Note that neither rbenv or rvm is involved).

Steps to reproduce are as follows.

First, create the directory gusteau_gem_path containing .gusteau.yml, Vagrantfile, and site-cookbooks/test/recipes/default.rb.

mkdir -p gusteau_gem_path/site-cookbooks/test/recipes
cd gusteau_gem_path

cat - > site-cookbooks/test/recipes/default.rb <<EOT
gem_package 'bundler'
EOT

cat - > .gusteau.yml <<EOT
environments:
  production:
    run_list:
      - recipe[test::default]
    nodes:
      box:
        host: 192.168.50.5
        user: vagrant
        password: vagrant
        vagrant:
          IP: 192.168.50.5
EOT

cat - > Vagrantfile <<EOT
Vagrant.configure('2') do |config|
  config.omnibus.chef_version = '11.6.0'  

  if ENV['WITH_GUSTEAU']
    Gusteau::Vagrant.detect(config) do |setup|
      setup.defaults.box = "precise32"
      setup.defaults.box_url = "http://files.vagrantup.com/precise32.box"
      setup.prefix = Time.now.to_i
    end
  else
    config.vm.box = "precise32"
    config.vm.provision :chef_solo do |chef|
     chef.cookbooks_path = ["site-cookbooks"]
     chef.add_recipe "test::default"
    end
  end
end
EOT

(In the above, feel free to change precise32.box to precise64.box in case you already have that downloaded)

First, provision without gusteau, and see that the bundler gem was installed properly:

vagrant up --no-provision

# confirm that bundler is not initially installed
vagrant ssh -- 'source /etc/profile.d/vagrant_ruby.sh; which bundle'
#    (NO RESULTS INITIALLY, AS EXPECTED)

vagrant provision
#    INFO: Processing gem_package[bundler] action install (test::default line 1)

# confirm that bundler was installed to system ruby
vagrant ssh -- 'source /etc/profile.d/vagrant_ruby.sh; which bundle'
#    /opt/vagrant_ruby/bin/bundle

Now lets provision via gusteau, and observe that bundler wasn't installed where expected:

# first, clean up from before
vagrant destroy -f

# WITH_GUSTEAU=1 is prepended to invocations to trigger condition in Vagrantfile enabling gusteau
WITH_GUSTEAU=1 vagrant up

WITH_GUSTEAU=1 gusteau converge production-box
#    GUSTEAU: 192.168.50.5> sudo -- sh -c 'unset GEM_HOME; unset GEM_PATH; chef-solo -c /etc/chef/solo.rb -j /etc/chef/dna.json --color'
#    INFO: Processing gem_package[bundler] action install (test::default line 1)

# observe see that bundle was never installed to system ruby
WITH_GUSTEAU=1 vagrant ssh -- 'source /etc/profile.d/vagrant_ruby.sh; which bundle'
#    (NO RESULTS, THIS IS A BUG)

The following confirms that bundler was actually installed to the omnibus ruby

WITH_GUSTEAU=1 vagrant ssh -- 'source /etc/profile.d/vagrant_ruby.sh; gem list | egrep "chef|bundler"'
#    chef (10.14.2)
WITH_GUSTEAU=1 vagrant ssh -- 'source /etc/profile.d/vagrant_ruby.sh; /opt/chef/embedded/bin/gem list | egrep "chef|bundler"'
#    bundler (1.1.5)
#    chef (11.6.0)
WITH_GUSTEAU=1 vagrant ssh -- 'cat /etc/profile.d/vagrant_ruby.sh'
#    PATH=$PATH:/opt/vagrant_ruby/bin

The following might be relevant:

@dergachev
Copy link
Author

Reported here: locomote/gusteau#40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment