LoginSignup
3
2

More than 5 years have passed since last update.

VagrantでChef Soloのバージョンを指定する方法

Last updated at Posted at 2014-12-30

あらまし

VagrantでChef soloを使っているとエラーが出た。

ERROR: undefined method `sensitive' for Chef::Resource::Template

ここを見るとどうもChef soloのバージョンが古いようなのでアップデートしようとしたのでその手順をまとめてみた。

流れ

まずエラーの確認。

==> rqbbitmq1: [2014-12-26T06:11:38+00:00] INFO: Forking chef instance to converge...
==> rqbbitmq1: [2014-12-26T06:11:38+00:00] DEBUG: Forked instance now converging
==> rqbbitmq1: [2014-12-26T06:11:38+00:00] INFO: *** Chef 11.8.2 ***
==> rqbbitmq1: [2014-12-26T06:11:38+00:00] INFO: Chef-client pid: 1921
==> rqbbitmq1: [2014-12-26T06:11:38+00:00] DEBUG: Building node object for rabbitmq1

...

[2014-12-26T06:11:39+00:00] ERROR: undefined method `sensitive' for Chef::Resource::Template

sensitiveというメソッドがないというのが原因と言われるが、Chefのドキュメントには載っている。

同じエラーでぐぐってみると以下の記事が見つかった。

ChefのMySQLクックブックでNoMethodError: Undefined Method `sensitive' for Chef::Resource::Executeの対処

そこではChefのsoloのバージョンが古いので上げれば動くようになると書いてあったが、Vagrantでchef soloのバージョンを上げる方法がわからないので調べる。

Vagrantのchef soloについてのドキュメントを見るとversion指定でいける模様。

Vagrantfile
conf.vm.provision :chef_solo do |chef|
  chef.log_level      = :debug
  chef.json           = load_node_json(conf.vm.hostname)
  chef.cookbooks_path = %w(../ berks-cookbooks)
  chef.version = '11.16.4'
end

実行

VagrantPlugins::Chef::Config::ChefSolo
Bringing machine 'rqbbitmq1' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:

chef solo provisioner:
* The following settings shouldn't exist: version
* The following settings shouldn't exist: version

なんかversionがないと怒られた。
ドキュメントを読み直すとinstallオプションにforceを指定しないといけない模様なので指定してみる。

Vagrantfile
conf.vm.provision :chef_solo do |chef|
  chef.log_level      = :debug
  chef.json           = load_node_json(conf.vm.hostname)
  chef.cookbooks_path = %w(../ berks-cookbooks)
  chef.install = 'force'
  chef.version = '11.16.4'
end

再度実行

Bringing machine 'rqbbitmq1' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:

chef solo provisioner:
* The following settings shouldn't exist: install, version
* The following settings shouldn't exist: install, version

おかしい・・・動かない・・・
しかたがないのでソースコードを覗くためにGithubのVagrantを見に行く。

どうやらこのコミットでversionとinstallが使えるようになったらしい。

versionは1.7.0からということで自分の手元を確認。

% vagrant -v
Vagrant 1.6.5

1.7以前だったのでバージョンアップ

% vagrant -v
Vagrant 1.7.1

これで上記のchef.install='force'chef.version='11.16.4'を指定したVagrantfileで再度実行

   rqbbitmq1: Installing Chef (11.16.4)...

無事に動いた。

結論

  • Vagrantのバージョンが1.7以降であればChef Soloのバージョンを指定してインストールが出来る
  • バージョンを指定したインストールをするために
    • Vagrantfileのprovisionでchef_soloを指定する
    • chef_soloの設定でinstall='force'version='任意'を指定する

参考

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2