写経環境を、vagrant-berkshelf から Vagrant + knife-solo + Berkshelf へと変更した

以前、GDG信州でvagrant-berkshelfを使った写経環境構築の発表をしましたが、その数日後にvagrant-berkshelfが非推奨になってしまいました*1
今のところは使えるものの、将来的なことも考えて、手元にある写経用の環境を Vagrant + knife-solo + Berkshelf へと更新しました。

環境


ちなみに、VMへのCookbook転送については、

のようにいくつか方法があったものの、今回はVagrantに任せることにしました。


なお、WindowsでのCookbook転送については、knife-soloのGitHubのIssueにMilestone(0.5.0)と書かれていました。
Provide better help if rsync isn't available · Issue #167 · matschaffer/knife-solo · GitHub


また、構築したものはGitHubにて公開しておきました。
thinkAmi/syakyo_env-ruby · GitHub



流れ

knife soloとBerkshelfのインストール

knife-soloとBerkshelfはBundlerで入れることにするため、Gemfileを作成します。
d:\hoge\Gemfile

source 'https://rubygems.org'

gem "knife-solo"
gem "berkshelf"

gem "win32-api", "~> 1.5.1", platforms: [:mingw, :x64_mingw]


なお、knife-solo 0.4.1の場合、何も指定しないとwin32-apiが1.4.8で入りますが、そのままではknife-solo実行時に以下のエラーが出ます。そのため、明示的にwin32-apiのバージョンを指定しておきます。

d:\hoge\fuga>bundle exec knife solo init chef-repo
DL is deprecated, please use Fiddle
d:/Develop/env/knife/vendor/bundle/ruby/2.0.0/gems/win32-api-1.4.8-x86-mingw32/lib/win32/api.rb:2:in `require': 126: 指定されたモジュールが見つかりません。   - d:/Develop/env/knife/vendor/bundle/ruby/2.0.0/gems/win32-api-1.4.8-x86-mingw32/lib/win32/ruby19/win32/api.so (LoadError)

また、念のためplatformsの指定もしておきました。platformsに指定するシンボル名は、以下を参考にしました。
Gemfile(5) - A format for describing gem dependencies for Ruby programs



Bundlerでパスを指定してローカルインストールします。

d:\hoge>bundle install --path vendor/bundle
DL is deprecated, please use Fiddle
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
〜略〜
Installing win32-api (1.5.1)
〜略〜
Installing knife-solo (0.4.1)
Using bundler (1.5.3)
Your bundle is complete!
It was installed into ./vendor/bundle
Post-install message from knife-solo:
Thanks for installing knife-solo!
If you run into any issues please let us know at:
  https://github.com/matschaffer/knife-solo/issues

If you are upgrading knife-solo please uninstall any old versions by running `gem clean knife-solo` to avoid any errors.

See http://bit.ly/CHEF-3255 for more information on the knife bug that causes this.


knifeの設定をします。色々と聞かれますが、今回はすべてEnterで進めます。

d:\hoge>bundle exec knife configure
DL is deprecated, please use Fiddle
WARNING: No knife configuration file found
〜略〜
Configuration file written to C:/Users//.chef/knife.rb
写経環境向けのCookbook作成

knifeを使ってリポジトリを作成します。knifeはBerkshelfと連携ができるようなので*2、同時にBerksfileも作成されます。

d:\hoge>mkdir fuga
d:\hoge>cd fuga
d:\hoge\fuga>bundle exec knife solo init chef-repo
DL is deprecated, please use Fiddle
Creating kitchen...
Creating knife.rb in kitchen...
Creating cupboards...
DL is deprecated, please use Fiddle
Setting up Berkshelf...


knifeを使ってCookbookのひな形を作ります。今回は、以下の内容でひな形を作ります。

  • Cookbook名: base
  • Cookbookの保存先: site-cookbooksディレクトリの下
d:\hoge\fuga>pushd chef-repo
d:\hoge\fuga\chef-repo>bundle exec knife cookbook create base -o site-cookbooks
DL is deprecated, please use Fiddle
** Creating cookbook base
** Creating README for cookbook: base
** Creating CHANGELOG for cookbook: base
** Creating metadata for cookbook: base


続いて環境用のレシピを編集します。内容は以下の通りです。

  • Ubuntuのみの設定
  • Gitの最新版をPPAからインストールする*3
  • Node.js、SQLiteBrowserをインストールする
  • Gitのブランチをターミナルに表示する
  • .gemrcを作成する

d:\hoge\fuga\chef-repo\site-cookbooks\base\recipes\default.rb

return unless node['platform'] == "ubuntu"

apt_repository 'git' do
    uri 'http://ppa.launchpad.net/git-core/ppa/ubuntu'
    distribution node[:lsb][:codename]
    components [:main]
    keyserver 'keyserver.ubuntu.com'
    key 'E1DF1F24'
    notifies :run, 'execute[apt-get update]', :immediately
end
package 'git'

package "nodejs"

package "sqlitebrowser"


script "show_git_branch" do
  interpreter "bash"
  user        "root"
  code <<-'EOL'
    wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -P /home/vagrant
    chmod -R 777 /home/vagrant/git-completion.bash
    echo source /home/vagrant/git-completion.bash >> /home/vagrant/.bashrc
    echo GIT_PS1_SHOWDIRTYSTATE=true >> /home/vagrant/.bashrc

    echo -n export PS1=\' >> /home/vagrant/.bashrc
    echo -n '\[\033[01;32m\]\u@\[\033[01;33m\] \w$(__git_ps1) \[\033[01;34m\]\$\[\033[00m\] ' >> /home/vagrant/.bashrc
    echo \' >> /home/vagrant/.bashrc

    source /home/vagrant/.bashrc
  EOL
end


script "create_gemrc" do
  interpreter "bash"
  user        "root"
  code <<-'EOL'
    echo 'install: --no-rdoc --no-ri' >> /home/vagrant/.gemrc
    echo -n 'update:  --no-rdoc --no-ri' >> /home/vagrant/.gemrc
    chmod -R 777 /home/vagrant/.gemrc
  EOL
end


上記の設定の他、サードパーティのCookbookを利用するため、knife solo init で作成したBerksfileを編集します。
d:\hoge\fuga\chef-repo\Berksfile

site :opscode

cookbook 'apt'
cookbook 'ruby_build'
cookbook 'rbenv', github: "fnichol/chef-rbenv"
cookbook 'sublime-text', github: 'ephess/sublime-text'


vagrant-berkshelfプラグインが無いため、事前にBerkshelfを実行してサードパーティのCookbookを取得しておきます。

d:\hoge\fuga\chef-repo>bundle exec berks install --path cookbooks
DL is deprecated, please use Fiddle
DL is deprecated, please use Fiddle
Installing apt (2.3.8) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks'
Installing ruby_build (0.8.0) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks'
Installing rbenv (0.7.3) from github: 'fnichol/chef-rbenv' with branch: 'master' over protocol: 'git'
Installing sublime-text (0.1.0) from github: 'ephess/sublime-text' with branch:'master' over protocol: 'git'
Installing java (1.19.2) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks'
Vagrant設定

Vagrantfileを作成します。

d:\hoge\fuga\chef-repo>popd
d:\hoge\fuga>vagrant init
A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.


作成したVagrantfileを編集します。chef.cookbooks_pathで、Cookbookがある相対パスを指定します。
d:\hoge\fuga\Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.hostname = "foo"
  
  config.vm.box = "ubuntu120403ja"
  config.vm.network :private_network, ip: "192.168.33.10"

  config.vm.provider :virtualbox do |vb|
    vb.gui = true
  end

  config.omnibus.chef_version = :latest


  config.vm.provision :chef_solo do |chef|
    chef.json = {
      rbenv: {
        user_installs: [{
          user: "vagrant",
          rubies: ["2.0.0-p451"],
          global: "2.0.0-p451",
          gems: {
            "2.0.0-p451" => [
              { name: "bundler"
              }
            ]
          }
        }]
      }
    }

    chef.cookbooks_path = ["./chef-repo/cookbooks", "./chef-repo/site-cookbooks"]


    chef.run_list = [
      "apt",
      "base",
      "ruby_build",
      "rbenv::user",
      "sublime-text"
    ]
  end
end
起動と確認

vagrant upで環境を構築します。

d:\hoge\fuga>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
〜略〜
[2014-02-26T08:27:53+00:00] INFO: execute[apt-get update] sending run action to
execute[apt-cache gencaches] (immediate)
[2014-02-26T08:27:53+00:00] INFO: execute[apt-cache gencaches] ran successfully
[2014-02-26T08:28:09+00:00] INFO: Chef Run complete in 841.560946263 seconds
[2014-02-26T08:28:09+00:00] INFO: Running report handlers
[2014-02-26T08:28:09+00:00] INFO: Report handlers complete


ターミナルで環境が構築されているかを確認します。

vagrant@ ~ $ rbenv versions list
  system
* 2.0.0-p451 (set by /home/vagrant/.rbenv/version)
vagrant@ ~ $ git --version
git version 1.9.0
vagrant@ ~ $ subl --version
Sublime Text 2 Build 2221


以上で完成です。

Windows7上で Vagrant + Chef solo + knife-solo の環境を構築した時に出会ったエラー

前回 は環境構築でしたが、試行錯誤する中で、いろいろとエラーに出会いました。
再び同じようなエラーに出会った時に読み返せるよう、エラーの内容と自分の対応を残しておきます。

環境

knife-soloのインストール時のエラー

knife-soloを --preオプションで入れたところ、以下のエラーとなりました。

gem install knife-solo --pre --no-ri --no-rdoc

ERROR:  While executing gem ... (Gem::DependencyError)
    Unable to resolve dependencies: knife-solo requires librarian (~> 0.0.20); c
hef requires net-ssh (~> 2.2.2)


自分の場合は、

gem install knife-solo -v 0.3.0.pre2 --no-ri --no-rdoc

のように、バージョンを指定してインストールすることで対応しました。



vagrant up」時のエラー (VERR_DISK_FULL)

d:\fuga>vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'hoge'...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["import", "C:/Users//.vagrant.d/boxes/hoge/virtualbox/box.ovf"]

Stderr: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Interpreting C:\Users\\.vagrant.d\boxes\hoge\virtualbox\box.ovf...
OK.
0%...
Progress state: VBOX_E_FILE_ERROR
VBoxManage.exe: error: Appliance import failed
VBoxManage.exe: error: Could not create the clone medium 'C:\Users\\VirtualBox VMs\ubuntu-cloudimg-precise-vagrant-i386\box-disk1.vmdk'.
VBoxManage.exe: error: VMDK: cannot write allocated data block in 'C:\Users\\VirtualBox VMs\ubuntu-cloudimg-precise-vagrant-i386/box-disk1.vmdk' (VERR_DISK_FULL)
VBoxManage.exe: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Appliance, interface IAppliance
VBoxManage.exe: error: Context: "int __cdecl handleImportAppliance(struct HandlerArg *)" at line 781 of file VBoxManageAppliance.cpp


途中のエラー「VERR_DISK_FULL」にもある通り、ディスクの容量が足りない時に表示されました。
そのため、不要になったVMは「vagrant destroy」で削除します。


なお、このエラーを調べているうちに、以下のパスが分かりました (いずれもデフォルトインストールした場合)。

項目
VagrantによるVMの作成先 %USERPROFILE%\VirtualBox VMs
VBoxManageの場所 C:\Program Files\Oracle\VirtualBox\VBoxManage


手元の環境ではCドライブの容量が少なかったため、VMの作成先をVirtualBoxのVBoxManage.exeにて変更しました。

# VMの作成先のフォルダを生成
d:\>mkdir vms

# 作成先を「d:\vms」の下へと変更
d:\vms>"C:\Program Files\Oracle\VirtualBox\VBoxManage" setproperty machinefolder d:\vms

参考:Chapter 8. VBoxManage



「knife-solo prepare」時のエラー

chef-repoの中で実行しなかった場合、最後のjsonファイル生成が失敗します。

knife solo prepare vagrant@192.168.33.10

Bootstrapping Chef...
(略)
Thank you for installing Chef!
Generating node config 'nodes/192.168.33.10.json'...
ERROR: Errno::ENOENT: No such file or directory - nodes/192.168.33.10.json

cookbookにて、apt-get update無し・「ubuntu-desktop」パッケージのインストールのみを記載し、実行した時のエラー

以下の通りです。ただ、再度同じように試してみた時は発生しませんでした...


D:\fuga\chef-repo\cookbooks\piyo\recipes\default.rb

package "ubuntu-desktop" do
  action :install
end


エラー内容

INFO: Processing package[ubuntu-desktop] action install (hello::default line 13)

================================================================================
Error executing action `install` on resource 'package[ubuntu-desktop]'
================================================================================

Chef::Exceptions::Exec
----------------------

apt-get -q -y install ubuntu-desktop=1.267 returned 100, expected 0

Resource Declaration:
---------------------

# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/piyo/recipes/default.rb

 12: #
 13: package "ubuntu-desktop" do
 14:   action :install
 15: end
 16:

Compiled Resource:
------------------

# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/piyo/recipes/default.rb :13:in `from_file'

package("ubuntu-desktop") do
  retry_delay 2
  retries 0
  recipe_name "default"
  action [:install]
  cookbook_name :piyo
  package_name "ubuntu-desktop"
end

ERROR: Running exception handlers
ERROR: Exception handlers complete
FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
FATAL: Chef::Exceptions::Exec: package[ubuntu-desktop] (hello::default line 13) had an error: Chef::Exceptions::Exec: apt-get -q -y
install ubuntu-desktop=1.267 returned 100, expected 0
Chef never successfully completed! Any errors should be visible in the output above. Please fix your recipes so that they properly complete.


returned 100は、エラーがあったことを示すようです。
参考:Man page of APT-GET



knife solo prepare 時のエラー (2013/5/1 追記)

  1. vagrant up の後、いろいろとやる
  2. vagrant destroy で削除
  3. Vagrantfile内のPrivate IP設定を変更しないまま、再度 vagrant up して再度仮想マシンを作る
  4. knife solo prepare で以下のエラーが発生した
ERROR: Net::SSH::HostKeyMismatch: fingerprint 23:bc:39:d7:f3:dd:9a:1a:01:f3:3b:a4:ec:3b:9d:02 does not match for "192.168.33.10"


原因は、以下のファイル「known_hosts」に、destroyした仮想マシンののエントリが残っていたためです。

%USERPROFILE%\.ssh\known_hosts


そのため、known_hostsから不要なエントリを削除すれば、knife solo prepare することができます。

Windows7上で Vagrant + Chef solo + knife-soloを使い、Ubuntu + ubuntu-desktopの環境を構築してみた

VirtualBoxを使って検証的な環境を作ったり壊したりしているのですが、いい加減手作業はツライので、最近目にするChef関連の環境を構築してみました。
なお、構築にあたり、naoyaさんの本が非常に役立ちました。ありがとうございました。
入門Chef Solo - Infrastructure as Code - 達人出版会


ちなみに、手元のWindows環境では rsnyc がうまく設定できなかったせいか、knife-soloの「knife solo cook」がうまくできませんでした。githubにもissueが上がっているようです。
ただ、「knife solo init」「knife solo prepare」がとても便利なので、knife-soloも環境構築に加えてあります。

環境

  • ホストOS: Windows7 x64
  • VirtualBox: 4.2.10 (4/8追記)
  • Ruby: 1.9.3p392
  • Git: 1.8.2 (SSHクライアントを兼務)
  • Vagrant: 1.1.5
  • Chef: 11.4.0
  • knife-solo: 0.3.0pre2
  • レシピ: Ubuntu12.04を作り、apt-getでubuntu-desktopを入れる (apt-getを試したかったため、日本語Remixではないです)

環境設定

Ruby

RubyInstallerでインストールします。
RubyInstaller for Windows

Git

Git for Windowsでインストールします。
Git

SSHクライアント

knife-soloで使うため、SSHクライアントを入れておきます。
Gitのものでも問題ないため、ssh.exeにパスを通しておきます。デフォルトインストールの場合、以下を環境変数PATHに設定しておきます。

C:\Program Files (x86)\Git\bin\
Vagrant

msiファイルが配布されているので、そちらでインストールします。
Vagrant

Chef

今回、ドキュメント系は不要なため、以下でインストールします。

gem install chef --no-ri --no-rdoc
knife-solo

「--pre」オプション付きではエラーで落ちたため、以下でバージョン指定してインストールしました。

gem install knife-solo -v 0.3.0.pre2 --no-ri --no-rdoc
knife-soloの設定

knife configure以降は、基本EnterでOKです。

knife configure
WARNING: No knife configuration file found
Where should I put the config file? [C:/Users//.chef/knife.rb] (Enter)
Please enter the chef server URL: [http://localhost:4000] (Enter)
Please enter an existing username or clientname for the API: [] (Enter)
Please enter the validation clientname: [chef-validator] (Enter)
Please enter the location of the validation key: [/etc/chef/validation.pem] (Enter)
Please enter the path to a chef repository (or leave blank): (Enter)

You must place your client key in:
  C:/Users//.chef/.pem
Before running commands with Knife!

You must place your validation key in:
  C:/etc//validation.pem
Before generating instance data with Knife!

Configuration file written to C:/Users//.chef/knife.rb

ただ、自分の場合は実行時に以下のエラーが出たため、「ffi」gemを追加しました。
エラー

custom_require.rb:36:in `require':cannot load such file -- ffi (LoadError)


追加

gem install ffi --no-ri --no-rdoc

作業の流れ

1. VagrantのBoxを追加

今回は、以下にて公開されているBoxを追加します。
その中のうち、ubuntu.comで配布されている「Official Ubuntu 12.04 daily Cloud Image i386 (No Guest Additions)」を「hoge」という名前で追加します。 (それなりに時間がかかります)
A list of base boxes for Vagrant - Vagrantbox.es


なお、セキュリティの関係などで共有boxを利用できない場合は、veeweeを利用します。
参考:vagrant ユーザよ、その VM は安全なのか? (veewee のすゝめ) - Hack like a rolling stone


実行

vagrant box add hoge http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-i386-disk1.box

Downloading with Vagrant::Downloaders::HTTP...
Downloading box: http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-i386-disk1.box
Downloading box: http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-i386-vagrant-disk1.box
Extracting box...5118927 / 345303040)
Cleaning up downloaded box...
Successfully added box 'hoge' with provider 'virtualbox'!
2. 任意の場所にフォルダを作成・移動

今回はD直下に「fuga」というフォルダを作成します。

cd /d d:\
mkdir fuga
cd fuga
3. knife-soloを使って、Chef用のリポジトリを作成

事前に作成しておきます。作成結果は特に表示されません。

d:\fuga>knife solo init chef-repo
4. vagrantのchefをアップデート

Vagrant1.1.5時点では、少し古いChef10.14.2が入っていたため、一度VMを起動してChefのアップデートを行います。なお、Chefのアップデートが不要な場合には省略も可能です。


まずは上記で追加したbox「hoge」をもとに、VMのひな形を作ります。

d:\fuga>vagrant init hoge

A `Vagrantfile` has been placed in this directory. You are nowready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on vagrantup.com` for more information on using Vagrant.


作成されたVagrantfileを編集し、chef-soloからSSH接続ができるよう、private networkの設定をします。
D:\fuga\Vagrantfile の23行目あたり

# Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # 以下をアンコメントします
  config.vm.network :private_network, ip: "192.168.33.10"

VMを起動します。

d:\fuga>vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
(略)
[default] -- /vagrant


Chefのアップデートの他、Chefで必要な「192.168.33.10.json」ファイルを自動生成するため、chef-repoの中に入って、knife solo prepareを実行します。

d:\fuga>cd chef-repo
d:\fuga\chef-repo>knife solo prepare vagrant@192.168.33.10

Bootstrapping Chef...


途中でVagrantのパスワードが求められるので、「vagrant」を入力します。

Enter the password for vagrant@192.168.33.10: vagrant


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6471  100  6471    0     0   4156      0  0:00:01  0:00:01 --:--:--  5039
Downloading Chef 11.4.0 for ubuntu...
Installing Chef 11.4.0
Selecting previously unselected package chef.
(Reading database ... 61658 files and directories currently installed.)
Unpacking chef (from .../chef_11.4.0_i386.deb) ...
Setting up chef (11.4.0-1.ubuntu.11.04) ...
Thank you for installing Chef!
Generating node config 'nodes/192.168.33.10.json'...


recipeまわりの設定をするため、一度停止します。

d:\fuga\chef-repo>vagrant halt
5. recipeへの記載

まずはcookbookを作成します。今回はcookbook「piyo」をcookbooksフォルダへ作成します。

d:\fuga\chef-repo>knife cookbook create piyo -o cookbooks

 ** Creating cookbook ubuntu-desktop
 ** Creating README for cookbook: ubuntu-desktop
 ** Creating CHANGELOG for cookbook: ubuntu-desktop
 ** Creating metadata for cookbook: ubuntu-desktop


以下のrecipeファイルを編集します。
D:\fuga\chef-repo\cookbooks\piyo\recipes\default.rb
apt-getの前にパッケージのアップデートを行わないと、エラーでapt-getができないため、最初にその処理を行なっています。
参考:cookbook - Installing multiple packages via Vagrant + Chef - Stack Overflow

# 「update package index」の処理を記載
execute "update package index" do
  command "apt-get update"
  ignore_failure true
  action :nothing
end.run_action(:run)

# update が終わったことをログ出力
log "done update"

# 「ubuntu-desktop」パッケージをインストールする
package "ubuntu-desktop" do
  action :install
end

# ubuntu-desktop のインストールが終わったことをログ出力
log "done install"
6. 各設定ファイルの設定

上記で作成したrecipeを使うよう、各ファイルを設定します。

  • d:\hoge\Vagrantfile

74行目辺りに追加します。

  # Enable provisioning with chef solo, specifying a cookbooks path, roles
  # path, and data_bags path (all relative to this Vagrantfile), and adding
  # some recipes and/or roles.
  config.vm.provision :chef_solo do |chef|
    # cookbookのありか。Vagrantfileからの相対パス
    chef.cookbooks_path = "./chef-repo/cookbooks"

    # 使用するrecipeの名前
    chef.add_recipe "piyo"
  end
  • D:\fuga\chef-repo\nodes\192.168.33.10.json
{"run_list":[" recipe [ piyo ]"]}
7. VMの起動・インストール・終了

再度起動します。起動中にChefが走り、ubuntu-desktopがインストールされます (結構時間がかかります)。

d:\fuga\chef-repo>vagrant up

# 結果
[default] -- /tmp/vagrant-chef-1/chef-solo-1/cookbooks
[default] Running provisioner: VagrantPlugins::Chef::Provisioner::ChefSolo...
Generating chef JSON and uploading...
Running chef-solo...
stdin: is not a tty
[2013-04-06T21:48:13+00:00] INFO: *** Chef 11.4.0 ***
[2013-04-06T21:48:14+00:00] INFO: Setting the run_list to ["recipe[piyo]"] from JSON
[2013-04-06T21:48:14+00:00] INFO: Run List is [recipe[piyo]]
[2013-04-06T21:48:14+00:00] INFO: Run List expands to [piyo]
[2013-04-06T21:48:14+00:00] INFO: Starting Chef Run for vagrant-ubuntu-precise-2
[2013-04-06T21:48:14+00:00] INFO: Running start handlers
[2013-04-06T21:48:14+00:00] INFO: Start handlers complete.
[2013-04-06T21:48:14+00:00] INFO: Processing execute[update package index] actin run (piyo::default line 11)
[2013-04-06T21:48:25+00:00] INFO: execute[update package index] ran successfull
[2013-04-06T21:48:25+00:00] INFO: Processing execute[update package index] actin nothing (piyo::default line 11)
[2013-04-06T21:48:25+00:00] INFO: Processing log[done update] action write (piyo::default line 18)
[2013-04-06T21:48:25+00:00] INFO: done update
[2013-04-06T21:48:25+00:00] INFO: Processing package[ubuntu-desktop] action install (piyo::default line 21)
[2013-04-06T22:50:14+00:00] INFO: Processing log[done install] action write (piyo::default line 26)
[2013-04-06T22:50:14+00:00] INFO: done install
[2013-04-06T22:50:14+00:00] INFO: Chef Run complete in 3720.292520252 seconds
[2013-04-06T22:50:14+00:00] INFO: Running report handlers
[2013-04-06T22:50:14+00:00] INFO: Report handlers complete


インストールが終わったら、インストール成功を確認するために、一度VMを停止します。

d:\fuga\chef-repo>vagrant halt
8. インストールの確認

Vagrantfileを修正し、GUI表示をするように変更します。
Vagrantfile の40行目あたり

  config.vm.provider :virtualbox do |vb|
    vb.gui = true
  end


起動して、GUIが表示されることを確認します。
recipeのapt-getのinstallなどが再実行されてしまいますが、特に問題なく起動します。気になる場合は、Vagrantファイルのrecipe設定を変更します。

d:\fuga\chef-repo>vagrant up


以上で、環境を構築することができました。
手作業に比べればかなり容易なため、これからもいろいろと試してみようと思います。



参考書籍

前述のnaoyaさんの書籍でChefについて理解した後は、SoftwareDesignの2012年10月号が参考になりました。
今でしたら、総集編に収録されているため、そちらのほうがおすすめです。

Software Design 総集編 【2001~2012】

Software Design 総集編 【2001~2012】