vagrant-berkshelfが上手にインストールされない事象に遭遇
vagrant-berkshelfプラグインをインストールしていたら, はまったのでメモ。
手順はこちらのブログを参考に。
EC2のChef SandboxをVagrant+BerkShelfでさくっと作る|クラスメソッド株式会社 開発ブログ
環境
状況
vagrantはインストール済の状態から、vagrant-berkshelfを新規インストールしようとしました。
$ gem install berkshelf $ vagrant plugin install vagrant-berkshelf
ここまではうまくいきました。
$ vagrant -v
すると、
/Applications/Vagrant/bin/../embedded/gems/bin/vagrant: No such file or directory - sysctl hw.ncpu Failed to load the "vagrant-berkshelf" plugin. View logs for more details. Vagrant version 1.2.4
対応
軽くググると、
https://github.com/RiotGames/vagrant-berkshelf/issues/47
を発見したので、手元で実行
$ VAGRANT_LOG=DEBUG vagrant -v (中略) ERROR root: Failed to load plugin: vagrant-berkshelf ERROR root: -- Error: #<NoMethodError: undefined method `[]' for nil:NilClass> ERROR root: -- Backtrace: ERROR root: /Users/nelmo/.vagrant.d/gems/gems/celluloid-0.14.1/lib/celluloid/cpu_counter.rb:7:in `<module:CPUCounter>' /Users/nelmo/.vagrant.d/gems/gems/celluloid-0.14.1/lib/celluloid/cpu_counter.rb:4:in `<module:Celluloid>' /Users/nelmo/.vagrant.d/gems/gems/celluloid-0.14.1/lib/celluloid/cpu_counter.rb:3:in `<top (required)>' /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' /Users/nelmo/.vagrant.d/gems/gems/celluloid-0.14.1/lib/celluloid.rb:497:in `<top (required)>' /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' /Users/nelmo/.vagrant.d/gems/gems/berkshelf-2.0.7/lib/berkshelf.rb:3:in `<top (required)>' /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' /Users/nelmo/.vagrant.d/gems/gems/vagrant-berkshelf-1.3.3/lib/berkshelf/vagrant.rb:11:in `<top (required)>' /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' /Users/nelmo/.vagrant.d/gems/gems/vagrant-berkshelf-1.3.3/lib/vagrant-berkshelf.rb:1:in `<top (required)>' /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require' /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require' /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require' /Applications/Vagrant/embedded/gems/gems/vagrant-1.2.4/lib/vagrant.rb:186:in `require_plugin' /Applications/Vagrant/embedded/gems/gems/vagrant-1.2.4/lib/vagrant/environment.rb:768:in `block in load_plugins' /Applications/Vagrant/embedded/gems/gems/vagrant-1.2.4/lib/vagrant/environment.rb:765:in `each' /Applications/Vagrant/embedded/gems/gems/vagrant-1.2.4/lib/vagrant/environment.rb:765:in `load_plugins' /Applications/Vagrant/embedded/gems/gems/vagrant-1.2.4/lib/vagrant/environment.rb:132:in `initialize' /Applications/Vagrant/embedded/gems/gems/vagrant-1.2.4/bin/vagrant:62:in `new' /Applications/Vagrant/embedded/gems/gems/vagrant-1.2.4/bin/vagrant:62:in `<top (required)>' /Applications/Vagrant/bin/../embedded/gems/bin/vagrant:23:in `load' /Applications/Vagrant/bin/../embedded/gems/bin/vagrant:23:in `<main>' INFO interface: error: Failed to load the "vagrant-berkshelf" plugin. View logs for more details. (後略)
とのこと。
スタックとレースの一番上のcpu_counter.rbを見てみると、 当該行あたりに,
module Celluloid module CPUCounter case RbConfig::CONFIG['host_os'][/^[A-Za-z]+/] when 'darwin' @cores = Integer(`sysctl hw.ncpu`[/\d+/]) # この行
sysctlを実行してるんですね。
ここで確認してみると、(なぜか)/usr/sbinにPATHが通っていないことが判明。そのせいでsysctlコマンドが実行できていなかったようです。
/usr/sbinにPATHを通してあげた結果、
$ vagrant -v Vagrant version 1.2.4
無事vagrant-berkshelfがloadされました。
あまりない事象かと思いますが、同じところで詰まっている方は一度PATHを参照してみて下さい。