LoginSignup
0
0

More than 5 years have passed since last update.

Vagrant1.1がリリースされてずいぶん経つけど、とりあえず1.0でBoxを作ってみる

Last updated at Posted at 2013-04-16

趣旨

  • Chefのクックブックを検証するための環境がほしい
  • 似たような環境を作ったり、何度も環境を作り直せるようにしたい
  • Veeweeを使えばVirtualBoxのイメージをサクッと用意できる
  • Vagrant1.1がリリースされているけど、ここでは1.0を使う

バージョン情報など

  • MacOSX 10.7
  • Ruby 1.9.3-p392(rbenv)
  • VirtualBox 4.2.12
  • veewee 0.3.7
  • vagrant 1.0.7

手順

VirtualBoxのインストール

Box作り

作業用ディレクトリの用意

mkdir veewee
cd veewee
rbenv local 1.9.3-p392

bundlerをインストール

gem install bundler
rbenv rehash
bundle init

Gemfileを記述

gem 'veewee'

gemのインストール(作業ディレクトリ以下に)

bundle install --path=vendor/bundle --binstubs

CentOS6.3のbaseboxを定義する

bin/vagrant basebox define centos6_3 'CentOS-6.3-x86_64-minimal'

作成されるファイル

definitions/centos6_3
├── base.sh
├── chef.sh
├── cleanup.sh
├── definition.rb
├── ks.cfg
├── puppet.sh
├── ruby.sh
├── vagrant.sh
├── virtualbox.sh
└── zerodisk.sh

定義の修正

  • base.sh
    • リリースに合うkernel-develがみつからないのでreleaseverを明示
  • definition.rb
    • iso_srcのURLを国内など近いものに変更
    • postinstall_files から ruby.sh, chef.sh, puppet.sh を除外
      • knife solo prepareでChef(と同梱する形でRubyも)をインストールするから
  • ks.cfg
    • lang, timezoneを修正

仮想マシンを作成し、Boxとしてエクスポート

bin/vagrant basebox build centos6_3
bin/vagrant basebox export centos6_3 centos6_3

→ centos6_3.boxができあがる。

Vagrantから利用する

パッケージ版のVagrantを別途インストールしてしまう(いかがなものか)

  • http://downloads.vagrantup.com/tags/v1.0.7 からダウンロード、インストール
  • 利用する側はchefやknife-soloがインストールされている環境なので、vagrantをgemとしてインストールしたくないという理由

先ほど作ったBoxをVagrantに登録する

vagrant box add centos6_3 /path/to/centos6_3.box

セットアップ、起動、接続

vagrant init centos6_3  # Vagrantfileが作成される
vagrant up
vagrant ssh

Vagrantについて

1.1からgemとしての提供は廃止され、パッケージのみとなった

Vagrant 1.0.x had the option to be installed as a RubyGem. This installation method has been removed for installers and packages only.

1.0用に作られたBoxは1.1以降でも使える

Box files made for Vagrant 1.0.x and VirtualBox continue to work with Vagrant 1.1+ and the VirtualBox provider.

将来的にはBoxを作る仕組みが提供されるらしい

A future release of Vagrant will provide additional mechanisms for automatically creating such images.

その他

  • VirtualBox Guest Additionsのためにgccなどをキックスタートでインストールしているが、実機にインストールするクックブックの作成を忘れがち(自分だけ?)
  • Githubに上げました

参考

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