LoginSignup
6
6

More than 5 years have passed since last update.

Windows8.1にVirtualBox + Vagrant + Chef + Berkshelf構築メモ

Last updated at Posted at 2014-08-16

事前準備に下記を実施

  • RubyInstallerでRubyのインストール(ruby 2.0.0p481 (2014-05-08) [x64-mingw32]で)
  • DevelopmentKitのインストール
  • Gem経由でBundlerのインストール(Bundler version 1.6.5)

VirtualBoxのインストール

バージョンは4.3.12を使用
(4.3.14も出ていたが、2014-08-16現在ではWindows8.1環境では起動できず)

Vagrantのインストール

Boxは下記を使用した
https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box

command
> vagrant box add [BOX名] [BOX URL]

> vagrant box list
rails (virtualbox, 0)

> cd [BOX格納ディレクトリ]
> vagrant init [BOX名]

下記を追記する

Vagrantfile
config.vm.box = "[BOX名]"

追記後仮想マシンを起動する

command
> vagrant up
> vagrant ssh
  • VT-x/AMD-Vを有効化されていない的なエラーが出たため、BIOSから有効化したら起動できた

下記を追記する

Vagrantfile
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "private_network", ip: "192.168.33.xxx"
config.ssh.forward_agent = true
config.vm.synced_folder "[共有フォルダパス]", "[仮想マシンのマウント先]"
  • Vagrantfileの中身はRubyのため、パスの円マークはエスケープが必要
command
> vagrant reload

VagrantとChefを連携させる

Chef, Berkshelfのインストール

command
> Bundle init
Gemfile
# A sample Gemfile
source "https://rubygems.org"

gem "chef","11.12.4"
gem "berkshelf","3.1.2"

gem "knife-solo"
gem "win32-process"
gem "windows-pr"
  • win32-processwindows-prはknife-solo実行時にエラーが出たため追加

DevelopmentKitの不具合?でTarが利用できず、Berkshelfのインストールでエラーが発生するため、
http://gnuwin32.sourceforge.net/packages/gtar.htm
から
http://gnuwin32.sourceforge.net/downlinks/tar-bin-zip.php
http://gnuwin32.sourceforge.net/downlinks/tar-dep-zip.php
をDLし、解答したファイルをDevelopmentKitのインストール先に移しておく

command
> Bundle install

RubyでOpenSSHを使用する際に証明書のエラーが出るため、環境変数SSL_CERT_FILE=[CA局の証明書パス]を登録必要がある
(証明書は http://curl.haxx.se/ca/cacert.pem を保存する)

Berkshelf実行時のエラーメッセージ
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

Vagrantファイルと同じディレクトリにBerksfileを作成する
(サンプルとしてgitをインストール)

Berksfile
source "https://api.berkshelf.com"

cookbook '[クックブック名]'

下記コマンドでクックブックをダウンロード

command
> bundle exec berks vendor [格納ディレクトリ名]

VagrantファイルにChef-soloの記述を追加

Vagrantfile
config.vm.provision "chef_solo" do |chef|
  chef.cookbooks_path = ["[クックブック格納ディレクトリ]"]
  chef.add_recipe '[クックブック名]'
end

仮想マシンに反映

command
> vagrant reload
> vagrant provision

仮想マシンにログインしてgit --versionで確認

6
6
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
6
6