CL LAB

HOME > CL LAB > BentoでVagrant Boxを作成する #opschef_ja

BentoでVagrant Boxを作成する #opschef_ja

 ★ 11

この記事は1年以上前に投稿されました。情報が古い可能性がありますので、ご注意ください。

BentoでVagrant Boxを作成する #opschef_ja

Bentoとは、VagrantのBoxを作成するツールであるVeeweeの定義ファイル集積プロジェクトです。

Bentoを使うことで、ChefのさまざまなテストのためのVagrant Boxを簡単に作成することができます。

Bentoのインストール

GitHubからBentoのレポジトリをcloneし、bundlerでインストールします。

VagrantやVeeweeといった必要なソフトウェアも同時にインストールされます。

% mkdir -p /var/local/cloud
% cd /var/local/cloud
% git clone git://github.com/opscode/bento.git
Cloning into 'bento'...
remote: Counting objects: 403, done.
remote: Compressing objects: 100% (279/279), done.
remote: Total 403 (delta 225), reused 256 (delta 101)
Receiving objects: 100% (403/403), 62.65 KiB | 66 KiB/s, done.
Resolving deltas: 100% (225/225), done.
% cd bento
% bundle install --verbose
:
:
:
Fetching https://github.com/mitchellh/vagrant.git
remote: Counting objects: 31032, done.
remote: Compressing objects: 100% (18198/18198), done.
remote: Total 31032 (delta 13834), reused 28903 (delta 11820)
Receiving objects: 100% (31032/31032), 9.63 MiB | 754 KiB/s, done.
Resolving deltas: 100% (13834/13834), done.
Fetching https://github.com/sneal/vagrant-windows.git
remote: Counting objects: 520, done.
remote: Compressing objects: 100% (258/258), done.
remote: Total 520 (delta 236), reused 474 (delta 197)
Receiving objects: 100% (520/520), 75.43 KiB | 53 KiB/s, done.
Resolving deltas: 100% (236/236), done.
Fetching https://github.com/jedi4ever/veewee.git
remote: Counting objects: 11667, done.
remote: Compressing objects: 100% (3808/3808), done.
remote: Total 11667 (delta 7801), reused 11450 (delta 7664)
Receiving objects: 100% (11667/11667), 3.57 MiB | 668 KiB/s, done.
Resolving deltas: 100% (7801/7801), done.
:
:
:
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
%
% bundle list
Gems included by the bundle:
* CFPropertyList (2.0.17)
* Platform (0.4.0)
* akami (1.2.0)
* ansi (1.3.0)
* builder (3.2.0)
* bundler (1.3.5)
* childprocess (0.3.9)
* diff-lcs (1.2.3)
* em-winrm (0.5.4)
* erubis (2.7.0)
* eventmachine (1.0.0.beta.3)
* excon (0.20.1)
* ffi (1.7.0)
* fission (0.4.0)
* fog (1.10.1)
* formatador (0.2.4)
* grit (2.5.0)
* gssapi (1.0.3)
* gyoku (1.0.0)
* highline (1.6.18)
* httpclient (2.2.0.2)
* httpi (0.9.7)
* i18n (0.6.4)
* json (1.7.7)
* libxml-ruby (2.6.0)
* little-plugger (1.1.3)
* log4r (1.1.10)
* logging (1.6.2)
* mime-types (1.22)
* mixlib-log (1.6.0)
* multi_json (1.7.2)
* net-scp (1.1.0)
* net-ssh (2.6.7)
* nokogiri (1.5.9)
* nori (1.1.5)
* open4 (1.3.0)
* popen4 (0.1.2)
* posix-spawn (0.3.6)
* progressbar (0.20.0)
* rack (1.5.2)
* rake (10.0.4)
* ruby-hmac (0.4.0)
* ruby-vnc (1.0.1)
* rubyntlm (0.1.1)
* savon (0.9.5)
* thor (0.18.1)
* uuidtools (2.1.3)
* vagrant (1.1.5 64e3608)
* vagrant-windows (0.2.0 fbe1164)
* veewee (0.3.7 164a10d)
* wasabi (1.0.0)
* winrm (1.1.2)
%

2013年4月24日現在、Bentoが持っているVirtualBox用定義は次の通りです。

% bundle exec veewee vbox list
The following definitions are available in /var/local/cloud/bento/bento
- centos-6.3-i386
- ubuntu-10.10
- debian-6.0.5-i386
- centos-6.0
- ubuntu-12.04
- ubuntu-12.04-i386
- windows-2012-standard
- ubuntu-10.04-i386
- centos-6.2
- centos-5.6
- windows-2008r2-standard
- windows-7-enterprise
- debian-6.0.5
- centos-6.2-i386
- centos-5.8-i386
- centos-6.3
- centos-5.9-i386
- centos-5.7
- centos-5.8
- ubuntu-11.10
- ubuntu-10.04
- centos-5.5
- centos-5.9
- centos-5.5-i386
- centos-6.4-i386
- ubuntu-11.04
- windows-8-enterprise
- centos-6.4
%

Ubuntu 12.04 (x86_64) Vagrant Boxの作成

例として、Ubuntu 12.04 (x86_64)のVagrant Boxを作成してみます。

途中、インストールISOファイルをダウンロードするかの質問があるのでYesと入力してください。

また、VirtualBoxが起動してOSインストールが行われますが、すべて自動で行われるため手を触れないでください。

% bundle exec veewee vbox build ubuntu-12.04
Downloading vbox guest additions iso v 4.1.18 - http://download.virtualbox.org/virtualbox/4.1.18/VBoxGuestAdditions_4.1.18.iso
Creating an iso directory
Checking if isofile VBoxGuestAdditions_4.1.18.iso already exists.
Full path: /var/local/cloud/bento/bento/iso/VBoxGuestAdditions_4.1.18.iso
Moving /tmp/open-uri20130424-19815-8s3rz to /var/local/cloud/bento/bento/iso/VBoxGuestAdditions_4.1.18.iso
Building Box ubuntu-12.04 with Definition ubuntu-12.04:
- debug : false
- cwd : /var/local/cloud/bento/bento
- force : false
- nogui : false
- auto : false
- checksum : false
- redirectconsole : false
- postinstall_include : []
- postinstall_exclude : []
We did not find an isofile here : /var/local/cloud/bento/bento/iso/ubuntu-12.04.2-server-amd64.iso.
The definition provided the following download information:
- Download url: http://releases.ubuntu.com/12.04/ubuntu-12.04.2-server-amd64.iso
- Md5 Checksum: af5f788aee1b32c4b2634734309cc9e9

Download? (Yes/No) Yes
Checking if isofile ubuntu-12.04.2-server-amd64.iso already exists.
Full path: /var/local/cloud/bento/bento/iso/ubuntu-12.04.2-server-amd64.iso
Moving /tmp/open-uri20130424-20105-1oyhx8t to /var/local/cloud/bento/bento/iso/ubuntu-12.04.2-server-amd64.iso
Creating vm ubuntu-12.04 : 384M - 1 CPU - Ubuntu_64
Creating new harddrive of size 40960, format VDI, variant Standard
Attaching disk: /var/local/cloud/virtualbox_vms/ubuntu-12.04/ubuntu-12.041.vdi
Mounting cdrom: /var/local/cloud/bento/bento/iso/ubuntu-12.04.2-server-amd64.iso
Mounting guest additions: /var/local/cloud/bento/bento/iso/VBoxGuestAdditions_4.1.18.iso
Finding unused TCP port in range: 7222 - 7262
Selected TCP port 7222
Finding unused TCP port in range: 7222 - 7262
Selected TCP port 7222
Waiting 10 seconds for the machine to boot
Finding unused TCP port in range: 7122 - 7199
Selected TCP port 7122
Starting a webserver :7122

Typing:[1]:
Typing:[2]:
Typing:[3]:
Typing:[4]: /install/vmlinuz
Typing:[5]:  auto
Typing:[6]:  console-setup/ask_detect=false
Typing:[7]:  console-setup/layoutcode=us
Typing:[8]:  console-setup/modelcode=pc105
Typing:[9]:  debconf/frontend=noninteractive
Typing:[10]:  debian-installer=en_US
Typing:[11]:  fb=false
Typing:[12]:  initrd=/install/initrd.gz
Typing:[13]:  kbd-chooser/method=us
Typing:[14]:  keyboard-configuration/layout=USA
Typing:[15]:  keyboard-configuration/variant=USA
Typing:[16]:  locale=en_US
Typing:[17]:  netcfg/get_domain=vm
Typing:[18]:  netcfg/get_hostname=vagrant
Typing:[19]:  noapic
Typing:[20]:  preseed/url=http://10.0.2.2:7122/preseed.cfg
Typing:[21]:  --
Typing:[22]:
Done typing.

Serving file /var/local/cloud/bento/bento/definitions/ubuntu-12.04/preseed.cfg
Shutting down for /var/local/cloud/bento/bento/definitions/ubuntu-12.04/preseed.cfg
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.........................................................................................
Transferring /tmp/.veewee_version20130424-20105-yrng3v to .veewee_version
..
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Transferring /tmp/.vbox_version20130424-20105-1jpi62f to .vbox_version
..
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Transferring /var/local/cloud/bento/bento/iso/VBoxGuestAdditions_4.1.18.iso to VBoxGuestAdditions_4.1.18.iso
...........................................................................................................................................................
:
:
:
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Transferring /tmp/.veewee_params20130424-20105-ost1yw to .veewee_params
..
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Transferring /var/local/cloud/bento/bento/definitions/ubuntu-12.04/update.sh to update.sh
..
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: chmod +x "update.sh"
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Transferring /var/local/cloud/bento/bento/definitions/ubuntu-12.04/chef-client.sh to chef-client.sh
..
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: chmod +x "chef-client.sh"
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Transferring /var/local/cloud/bento/bento/definitions/ubuntu-12.04/vagrant.sh to vagrant.sh
..
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: chmod +x "vagrant.sh"
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Transferring /var/local/cloud/bento/bento/definitions/ubuntu-12.04/networking.sh to networking.sh
..
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: chmod +x "networking.sh"
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Transferring /var/local/cloud/bento/bento/definitions/ubuntu-12.04/sudoers.sh to sudoers.sh
..
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: chmod +x "sudoers.sh"
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Transferring /var/local/cloud/bento/bento/definitions/ubuntu-12.04/cleanup.sh to cleanup.sh
..
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: chmod +x "cleanup.sh"
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Transferring /var/local/cloud/bento/bento/definitions/ubuntu-12.04/minimize.sh to minimize.sh
..
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: chmod +x "minimize.sh"
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo 'vagrant'|sudo -S sh './update.sh'
Ign http://us.archive.ubuntu.com precise InRelease
Ign http://us.archive.ubuntu.com precise-updates InRelease
Ign http://us.archive.ubuntu.com precise-backports InRelease
:
:
:
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo 'vagrant'|sudo -S sh './chef-client.sh'
[sudo] password for vagrant: --2013-04-24 06:01:56--  http://opscode.com/chef/install.sh
Resolving opscode.com (opscode.com)... 184.106.28.83
Connecting to opscode.com (opscode.com)|184.106.28.83|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.opscode.com/chef/install.sh [following]
--2013-04-24 06:01:56--  http://www.opscode.com/chef/install.sh
Resolving www.opscode.com (www.opscode.com)... 184.106.28.82
Connecting to www.opscode.com (www.opscode.com)|184.106.28.82|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6470 (6.3K) [application/x-sh]
Saving to: `STDOUT'

100%[======================================>] 6,470       38.7K/s   in 0.2s

2013-04-24 06:01:57 (38.7 KB/s) - written to stdout [6470/6470]

Downloading Chef  for ubuntu...
Installing Chef
Selecting previously unselected package chef.
(Reading database ... 53284 files and directories currently installed.)
Unpacking chef (from .../tmp.OIZReNax/chef__amd64.deb) ...
Setting up chef (11.4.4-1.ubuntu.11.04) ...
Thank you for installing Chef!
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo 'vagrant'|sudo -S sh './vagrant.sh'
[sudo] password for vagrant: --2013-04-24 06:02:24--  http://download.virtualbox.org/virtualbox/4.1.18/VBoxGuestAdditions_4.1.18.iso
Resolving download.virtualbox.org (download.virtualbox.org)... 137.254.16.69
Connecting to download.virtualbox.org (download.virtualbox.org)|137.254.16.69|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://dlc.sun.com.edgesuite.net/virtualbox/4.1.18/VBoxGuestAdditions_4.1.18.iso [following]
--2013-04-24 06:02:24--  http://dlc.sun.com.edgesuite.net/virtualbox/4.1.18/VBoxGuestAdditions_4.1.18.iso
Resolving dlc.sun.com.edgesuite.net (dlc.sun.com.edgesuite.net)... 72.246.190.66, 72.246.190.67
Connecting to dlc.sun.com.edgesuite.net (dlc.sun.com.edgesuite.net)|72.246.190.66|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 52164608 (50M) [application/octet-stream]
Saving to: `VBoxGuestAdditions_4.1.18.iso.1'

100%[======================================>] 52,164,608  7.52M/s   in 7.9s

2013-04-24 06:02:32 (6.30 MB/s) - `VBoxGuestAdditions_4.1.18.iso.1' saved [52164608/52164608]

mount: warning: /tmp/vbox seems to be mounted read-only.
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.1.18 Guest Additions for Linux.........
VirtualBox Guest Additions installer
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.

Building the main Guest Additions module ...fail!
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions ...done.
Installing the Window System drivers ...fail!
(Could not find the X.Org or XFree86 Window System.)
--2013-04-24 06:02:58--  http://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub
Resolving github.com (github.com)... 204.232.175.90
Connecting to github.com (github.com)|204.232.175.90|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub [following]
--2013-04-24 06:02:59--  https://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub
Connecting to github.com (github.com)|204.232.175.90|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub [following]
--2013-04-24 06:03:00--  https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub
Resolving raw.github.com (raw.github.com)... 199.27.75.133
Connecting to raw.github.com (raw.github.com)|199.27.75.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 409 [text/plain]
Saving to: `/home/vagrant/.ssh/authorized_keys'

100%[======================================>] 409         --.-K/s   in 0s

2013-04-24 06:03:01 (13.7 MB/s) - `/home/vagrant/.ssh/authorized_keys' saved [409/409]

 

Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo 'vagrant'|sudo -S sh './networking.sh'
[sudo] password for vagrant: Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo 'vagrant'|sudo -S sh './sudoers.sh'
[sudo] password for vagrant: Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo 'vagrant'|sudo -S sh './cleanup.sh'
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo 'vagrant'|sudo -S sh './minimize.sh'
dd: writing `/EMPTY': No space left on device
38105+0 records in
38104+0 records out
39955685376 bytes (40 GB) copied, 97.4388 s, 410 MB/s
The box ubuntu-12.04 was built successfully!
You can now login to the box with:
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 7222 -l vagrant 127.0.0.1
%

The box ubuntu-12.04 was built successfully!と表示され、プロンプトが返ってきたら作成成功です。

引き続き、出来上がったマシンイメージを検査します。

% bundle exec veewee vbox validate ubuntu-12.04
Checking user - OK
Checking sudo - OK
Checking ruby - FAILED
Command: . /etc/profile ;ruby --version 2> /dev/null 1> /dev/null;  echo $?
Expected string 0
Output:
Checking gem - FAILED
Command: . /etc/profile ;gem --version 2> /dev/null 1> /dev/null;  echo $?
Expected string 0
Output:
Checking chef - OK
Checking puppet - FAILED
Command: . /etc/profile ;puppet --version 2> /dev/null 1>/dev/null; echo $?
Expected string 0
Output:
Checking shared folder - FAILED
Command: mount|grep veewee-validation; echo $?
Expected string 0
Output:
%

user、sudo、chefがOKならば、ruby、gem、puppet、shared folderがFAILEDでも構いません。

では、Vagrant Boxに変換します。

% bundle exec veewee vbox export ubuntu-12.04
Vagrant requires the box to be shutdown, before it can export
Sudo also needs to work for user vagrant
Performing a clean shutdown now.
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo 'shutdown -P now' > /tmp/shutdown.sh
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: chmod +x /tmp/shutdown.sh
Waiting for ssh login on 127.0.0.1 with user vagrant to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo 'vagrant'|sudo -S sh '/tmp/shutdown.sh'
..
Machine ubuntu-12.04 is powered off cleanly
Creating a temporary directory for export
Adding additional files
Creating Vagrantfile
Exporting the box
Executing VBoxManage export ubuntu-12.04 --output /tmp/d20130424-32486-6y9xfc/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 'ubuntu-12.04' '/var/local/cloud/bento/bento/ubuntu-12.04.box'
 

 

To use it:
vagrant init 'ubuntu-12.04'
vagrant up
vagrant ssh
%

自動的にVirtualBoxが停止され、Vagrant Boxが生成されます。

このように、Bentoを用いることで、時間はかかりますが自前でChef向けのVagrant Boxを作成することができます。カスタマイズする場合はDefinitionsCustomizing Definitionsを参考にしてください。

CL LAB Mail Magazine

CL LABの情報を逃さずチェックしよう!

メールアドレスを登録すると記事が投稿されるとメールで通知します。

メールアドレス: 登録

※登録後メールに記載しているリンクをクリックして認証してください。

Related post