SSブログ

veeweeでboxを自前で作る [Chef]

Vagrantの提供されているboxは、タイムゾーンがUTCであったり、LANGの設定がCだったりします。なによりストレージサイズが200GBでテスト用には、いささか大きいです。100GBでいいと思ってます。
と注文が多いので、自前でboxを作成することにしました。

veewee環境を作成する


veeweeは、Rubyのgemなので、bundlerがあると便利なので、追加インストールします。
C:\Users\hoge> gem install bundler --no-rdoc --no-ri Fetching: bundler-1.3.5.gem (100%) Successfully installed bundler-1.3.5 1 gem installed


Veeweeのgemは、メンテナンスされていないので、gitからインストールします。
C:\Users\hoge> mkdir veewee C:\Users\hoge> git config --global core.autocrlf false C:\Users\hoge> git clone git://github.com/jedi4ever/veewee.git Cloning into 'veewee'... remote: Counting objects: 12755, done. remote: Compressing objects: 100% (4781/4781), done. remote: Total 12755 (delta 8431), reused 11957 (delta 7773) Receiving objects: 100% (12755/12755), 3.78 MiB | 1.52 MiB/s, done. Resolving deltas: 100% (8431/8431), done. Checking out files: 100% (1544/1544), done.

git clone が終わったら bundle install を実行します。(必要に応じてプロキシの設定をしておくこと)
C:\Users\hoge\veewee>set http_proxy=http://proxy.xxxxxx.co.jp:8080/ C:\Users\hoge\veewee>bundle install Fetching http://github.com/hh/em-winrm.git remote: Counting objects: 144, done. remote: Compressing objects: 100% (100/100), done. rRemote: Total 144 (delta 69), reused 113 (delta 43)eceiving objects: 51% (74/1 Receiving objects: 79% (114/144) Receiving objects: 100% (144/144), 23.52 KiB | 0 bytes/s, done. Resolving deltas: 100% (69/69), done. Fetching gem metadata from http://rubygems.org/........ Fetching gem metadata from http://rubygems.org/.. Resolving dependencies... Installing rake (10.1.0) Installing CFPropertyList (2.0.17) Installing Platform (0.4.0) Installing builder (3.2.2) Installing gyoku (1.1.0) Installing akami (1.2.0) Installing ansi (1.3.0) Using bundler (1.3.5) Using childprocess (0.3.9) Installing diff-lcs (1.2.4) Using mixlib-log (1.6.0) Installing uuidtools (2.1.4) Installing gssapi (1.0.3) Installing httpclient (2.2.0.2) Installing little-plugger (1.1.3) Installing logging (1.6.2) Installing rubyntlm (0.1.1) Installing rack (1.5.2) Installing httpi (0.9.7) Installing nori (1.1.5) Installing wasabi (1.0.0) Installing savon (0.9.5) Installing winrm (1.1.2) Using em-winrm (0.5.4.rc.1) from http://github.com/hh/em-winrm.git (at 3174560) Installing excon (0.25.3) Installing fission (0.4.0) Installing formatador (0.2.4) Using mime-types (1.25) Installing multi_json (1.8.0) Installing net-ssh (2.7.0) Installing net-scp (1.1.2) Installing ruby-hmac (0.4.0) Installing fog (1.15.0) Installing posix-spawn (0.3.6) Installing grit (2.5.0) Using highline (1.6.19) Using i18n (0.6.5) Installing json (1.8.0) Using log4r (1.1.10) Installing open4 (1.3.0) Installing os (0.9.6) Installing popen4 (0.1.2) Installing progressbar (0.20.0) Installing rspec-core (2.14.5) Installing rspec-expectations (2.14.2) Installing rspec-mocks (2.14.3) Installing rspec (2.14.1) Installing ruby-vnc (1.0.1) Installing sane (0.25.6) Using thor (0.18.1) Installing whichr (0.3.6) Using veewee (0.3.8.dev) from source at C:/Users/hoge/veewee Your bundle is complete! Gems in the group kvm were not installed. Use `bundle show [gemname]` to see where a bundled gem is installed. C:\Users\hoge\veewee>

veeweeで提供しているテンプレートの一覧を確認

コマンドプロンプトから以下のコマンドで一覧を参照できるが、表示しきれません。
C:\Users\hoge\veewee> bundle exec veewee vbox templates
以下のURLから一覧を確認できます。
https://github.com/jedi4ever/veewee/tree/master/templates

veeweeのテンプレートを取得し、カスタマイズ

一覧から「CentOS-6.4-x86_64-minimal」を使うことにします。 選んだテンプレートの名前を指定して veewee vbox define を実行します。
C:\Users\hoge\veewee> bundle exec veewee vbox define 'centos64-ja' 'CentOS-6.4-x86_64-minimal'
テンプレートファイルは、以下に作成されます。
C:\Users\hoge\veewee\definitions\centos64-ja
作成する box の設定をカスタマイズするので、作成したテンプレートのファイルを編集します。
ここではまずは ks.cfg を編集し、以下の項目を変更して日本語環境とします。
[ks.cfg]
install cdrom lang ja_JP.UTF-8 keyboard jp106 network --bootproto=dhcp rootpw --iscrypted $1$damlkd,f$UC/u5pUts5QiU3ow.CSso/ firewall --enabled --service=ssh authconfig --enableshadow --passalgo=sha512 selinux --disabled timezone Asia/Tokyo bootloader --location=mbr text skipx zerombr clearpart --all --initlabel autopart auth --useshadow --enablemd5 firstboot --disabled reboot %packages --nobase @core %end %post /usr/bin/yum -y install sudo /usr/sbin/groupadd veewee /usr/sbin/useradd veewee -g veewee -G wheel echo "veewee"|passwd --stdin veewee echo "veewee ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/veewee chmod 0440 /etc/sudoers.d/veewee %end
次に definition.rb を編集し、以下などを環境に合わせ適宜変更します。
[definition.rb]
Veewee::Session.declare({ :cpu_count => '1', :memory_size=> '1024', :disk_size => '102400', :disk_format => 'VDI', :hostiocache => 'off', :os_type_id => 'RedHat6_64', :iso_file => "CentOS-6.4-x86_64-minimal.iso", :iso_src => "http://ftp.jaist.ac.jp/pub/Linux/CentOS/6.4/isos/x86_64/CentOS-6.4-x86_64-minimal.iso", :iso_md5 => "4a5fa01c81cc300f4729136e28ebe600", :iso_download_timeout => 1000, :boot_wait => "10", :boot_cmd_sequence => [ ' text ks=http://%IP%:%PORT%/ks.cfg' ], :kickstart_port => "7122", :kickstart_timeout => 10000, :kickstart_file => "ks.cfg", :ssh_login_timeout => "10000", :ssh_user => "veewee", :ssh_password => "veewee", :ssh_key => "", :ssh_host_port => "7222", :ssh_guest_port => "22", :sudo_cmd => "echo '%p'|sudo -S sh '%f'", :shutdown_cmd => "/sbin/halt -h -p", :postinstall_files => [ "base.sh", "chef.sh", #"puppet.sh", "vagrant.sh", "virtualbox.sh", #"vmfusion.sh", "cleanup.sh", "zerodisk.sh" ], :postinstall_timeout => 10000 })

テンプレートへのプロキシの設定

このままではプロキシ環境に祟られるので、base.sh,chef.sh,virtualbox.sh,cleanup.shの先頭に設定を追加します。
export http_proxy=http://proxy.xxxxxx.co.jp:8080/ export https_proxy=http://proxy.xxxxxx.co.jp:8080/
vagrant.shには、先頭に以下の行を追加します。
# Vagrant specific cat <> /etc/wgetrc http_proxy=http://proxy.xxxxxx.co.jp:8080/ https_proxy=http://proxy.xxxxxx.co.jp:8080/ EOF

仮想マシンの作成

テンプレートのカスタマイズが完了したら veewee vbox build を実行します。
C:\Users\hoge\veewee>veewee vbox build centos64-ja

仮想マシンをエクスポートし、自前のboxを作成

仮想マシンを停止したら、コマンドプロンプトから以下のコマンドを実行し、作成した仮想マシンを box ファイルへとエクスポートしてboxを作成します。
C:\Users\hoge\veewee>bundle exec veewee vbox export centos64-ja DL is deprecated, please use Fiddle Creating a temporary directory for export Adding additional files Creating Vagrantfile Exporting the box Executing "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" export centos64-ja --output C:/Users/hoge/AppData/Local/Temp/d20130913-4052-301rgm/box.ovf 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Successfully exported 1 machine(s). Packaging the box Cleaning up temporary directory To import it into vagrant type: vagrant box add 'centos64-ja' 'C:/Users/hoge/veewee/centos64-ja.box' To use it: vagrant init 'centos64-ja' vagrant up vagrant ssh C:\Users\hoge\veewee>

vagrantの環境に作成したboxを追加

作成した box を使用するには、外部の box を使う時と同様、まずは vagrant に box add する必要があります。
C:\Users\hoge> vagrant box add centos64-ja
追加されるbox
C:\Users\hoge\.vagrant.d\boxes\centos64-ja\centos64-ja.box

vagrant初期化

問題なく追加できたら、仮想マシン用のディレクトリを作成し、vagrant init を実行します。
C:\Users\hoge>vagrant init centos64-ja 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.
これで vagrant 用の新たな仮想マシンが作成されるので、vagrant up すれば仮想マシンが起動できます。
C:\Users\hoge> vagrant up

タグ:Chef veewee

共通テーマ:blog

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。