VagrantのプロビジョニングでChef Soloを使ってみる その1
まずChef-Soloをインストールするためのプラグインなどなどの準備
準備開始
vagrant-omnibus
をインストールする。
$ vagrant plugin install vagrant-omnibus Installing the 'vagrant-omnibus' plugin. This can take a few minutes... Installed the plugin 'vagrant-omnibus (1.4.1)'!
vagrant-berkshelf
もインストールする。
$ vagrant plugin install vagrant-berkshelf Installing the 'vagrant-berkshelf' plugin. This can take a few minutes... Installed the plugin 'vagrant-berkshelf (1.3.7)'!
なんか古いっぽいので一回アンインストールしていれなおし。
ここを参考に
$ vagrant plugin uninstall vagrant-berkshelf Uninstalling the 'vagrant-berkshelf' plugin... $ vagrant plugin install vagrant-berkshelf --plugin-version '>= 2.0.1' Installing the 'vagrant-berkshelf --version '>= 2.0.1'' plugin. This can take a few minutes... Installed the plugin 'vagrant-berkshelf (2.0.1)'!
berkshelfをgem i berkshelf
でインストール
berkshelfの準備
公式サイトを参考にします
$ berks cookbook myapp create my-cookbook/files/default create my-cookbook/templates/default create my-cookbook/attributes create my-cookbook/libraries create my-cookbook/providers create my-cookbook/recipes create my-cookbook/resources create my-cookbook/recipes/default.rb create my-cookbook/metadata.rb create my-cookbook/LICENSE create my-cookbook/README.md create my-cookbook/CHANGELOG.md By default, this cookbook was generated to support bundler, however, bundler is not installed. To skip support for bundler, use --no-bundler To install bundler: gem install bundler create my-cookbook/Berksfile create my-cookbook/Thorfile create my-cookbook/chefignore create my-cookbook/.gitignore create my-cookbook/Gemfile create my-cookbook/Vagrantfile
ん?こっちにもVagrantfileができたぞ?
berkshelfさんはVagrant使うのが当たり前的なかたちなのかな?
gitignoreとかもあるしもうそういう時代なんだろうな。。。
でもやりすぎじゃね?なんか邪魔とか思っちゃう。
よくわからないけどもこっちのディレクトリはまずはさわらない
cp -p ./my-cookbook/Berksfile .
でBarksfileをコピーして、nginxのインストールを追加
$ cat Berksfile source "https://api.berkshelf.com" metadata cookbook "nginx", "~> 2.6"
続いてVagrantfile
config.omnibus.chef_version = :latest config.berkshelf.enabled = true config.vm.provision :chef_solo do |chef| chef.run_list = ["my-cookbook"] end
起動してみる!!!
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'centos6.5'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: chefSolo_default_1402205464311_41175 Berkshelf::BerksfileReadError: An error occurred while reading the Berksfile: Could not open or read: '/Users/akira/vagrant/chefSolo/metadata.rb' Akira-no-MacBook-Pro:chefSolo akira$
metadata.rbが見えないと。
カレントにコピーしたBerksfileをmy-cookbookにコピーして、Vagrantfileに以下を追加
config.berkshelf.berksfile_path = "./my-cookbook/Berksfile"
ふぉおおおおおお、きどうした!
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... : ==> default: Thank you for installing Chef! ==> default: Running provisioner: chef_solo... Generating chef JSON and uploading... ==> default: Running chef-solo... ==> default: [2014-06-08T05:39:52+00:00] INFO: Forking chef instance to converge... ==> default: [2014-06-08T05:39:52+00:00] WARN: ==> default: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ==> default: SSL validation of HTTPS requests is disabled. HTTPS connections are still ==> default: encrypted, but chef is not able to detect forged replies or man in the middle ==> default: attacks. ==> default: ==> default: To fix this issue add an entry like this to your configuration file: ==> default: ==> default: `` ==> default: # Verify all HTTPS connections (recommended) ==> default: ssl_verify_mode :verify_peer ==> default: ==> default: # OR, Verify only connections to chef-server ==> default: verify_api_cert true ==> default: `` ==> default: ==> default: To check your SSL configuration, or troubleshoot errors, you can use the ==> default: `knife ssl check` command like so: ==> default: ==> default: `` ==> default: knife ssl check -c /tmp/vagrant-chef-3/solo.rb ==> default: `` ==> default: ==> default: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ==> default: [2014-06-08T05:39:52+00:00] INFO: *** Chef 11.12.8 *** ==> default: [2014-06-08T05:39:52+00:00] INFO: Chef-client pid: 2175 ==> default: [2014-06-08T05:40:55+00:00] INFO: Setting the run_list to ["my-cookbook"] from CLI options ==> default: [2014-06-08T05:40:55+00:00] INFO: Run List is [recipe[my-cookbook]] ==> default: [2014-06-08T05:40:55+00:00] INFO: Run List expands to [my-cookbook] ==> default: [2014-06-08T05:40:55+00:00] INFO: Starting Chef Run for vagrant-centos65.vagrantup.com ==> default: [2014-06-08T05:40:55+00:00] INFO: Running start handlers ==> default: [2014-06-08T05:40:55+00:00] INFO: Start handlers complete. ==> default: [2014-06-08T05:40:55+00:00] INFO: Chef Run complete in 0.223080628 seconds ==> default: [2014-06-08T05:40:55+00:00] INFO: Running report handlers ==> default: [2014-06-08T05:40:55+00:00] INFO: Report handlers complete Akira-no-MacBook-Pro:chefSolo akira$
でもnginxはいってない。なんぞ????
とりあえずWARNはここみて対応
結論、ここがおかしかった。
chef.run_list = ["nginx"]
chefの概念を理解しないでやろうとするからこういうことになる。
次回は今回のいろいろな失敗を整理してみたい。