Vagrant Cloud上に公開されたBoxを利用する方法

2014年07月25日 19時05分

201407251905VVAW00.png

はじめに

本ブログでは、Vagrantに関する記事を公開 していますが、Vagrant 1.5で追加されたVagrant Cloudの機能については取り上げていません。 そこで今回は、Vagrant Cloud上に公開されたBoxをローカルマシン上で利用する方法を解説します。

前提条件

作業の前提条件は、下記のとおりです。

ソフトウエアバージョン
OSWindows 7 Ultimate 32bit
CygwinSetup Version 2.831
VirtualBox4.3.12 r93733
Vagrant1.6.3
Vagrant Cloudは、バージョン1.5以上のVagrantで動作しますので、必ずバージョン1.5以上のVagrantをインストールして下さい。

Vagrat Cloud上のBoxを利用する

バージョン1.4以下のVagrantでは、A list of base boxes for Vagrantから、Boxイメージを追加して利用していましたが、バージョン1.5以上のVagrantでは、Vagrant Cloudが利用できるため、先のサイトのBoxイメージの他にVagrant Cloud上に公開されたBoxを利用することができます。

  1. Vagrant Cloud上から追加するイメージを検索する

    Discover ready-made boxesから、追加するBoxを検索します。

    201407251905VVAW01.png
  2. Vagrant Cloud上のBoxを追加する

    今回は、chef/centos-6.5を追加します。
    コマンドを実行すると、どのVM用のイメージをダウンロードするか聞かれますので、virtual boxを指定しています。

    $ vagrant box add chef/centos-6.5
    
    201407251905VVAW02.png
    ==> box: Loading metadata for box 'chef/centos-6.5'
        box: URL: https://vagrantcloud.com/chef/centos-6.5
    This box can work with multiple providers! The providers that it
    can work with are listed below. Please review the list and choose
    the provider you will be working with.
    
    1) virtualbox
    2) vmware_desktop
    
    Enter your choice: 1
    ==> box: Adding box 'chef/centos-6.5' (v1.0.0) for provider: virtualbox
        box: Downloading: https://vagrantcloud.com/chef/centos-6.5/version/1/provider/virtualbox.box
        box:
    ==> box: Successfully added box 'chef/centos-6.5' (v1.0.0) for 'virtualbox'!
    
  3. Box一覧の表示

    listコマンドを使用して、Vagrantに追加されたBox名を表示します。
    box addコマンドで指定したBoxが、追加されたことが確認できます。

    $ vagrant box list
    
    201407251905VVAW03.png
    CentOS-6.5-i386-php54   (virtualbox, 0)
    CentOS-6.5-i386-php55   (virtualbox, 0)
    CentOS-6.5-x86_64-php54 (virtualbox, 0)
    CentOS-6.5-x86_64-php55 (virtualbox, 0)
    chef/centos-6.5         (virtualbox, 1.0.0)
    
  4. Vagrantfileの作成

    Box名を指定して、Vagrantfileを作成します。

    $ vagrant init chef/centos-6.5
    
    201407251905VVAW04.png
    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.
    
  5. Box起動

    Vagrant Cloudから追加したBoxを起動します。

    $ vagrant up
    
    201407251905VVAW05.png
    201407251905VVAW06.png
    vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Importing base box 'chef/centos-6.5'...
    ==> default: Matching MAC address for NAT networking...
    ==> default: Checking if box 'chef/centos-6.5' is up to date...
    ==> default: Setting the name of the VM: vagrant_default_1406270414789_85089
    ==> default: Clearing any previously set network interfaces...
    ==> default: Preparing network interfaces based on configuration...
        default: Adapter 1: nat
    ==> default: Forwarding ports...
        default: 22 => 2222 (adapter 1)
    ==> default: Booting VM...
    ==> default: Waiting for machine to boot. This may take a few minutes...
        default: SSH address: 127.0.0.1:2222
        default: SSH username: vagrant
        default: SSH auth method: private key
        default: Warning: Connection timeout. Retrying...
        default: Warning: Connection timeout. Retrying...
        default: Warning: Remote connection disconnect. Retrying...
    ==> default: Machine booted and ready!
    GuestAdditions versions on your host (4.3.12) and guest (4.3.8) do not match.
    Loaded plugins: fastestmirror
    Determining fastest mirrors
     * base: www.ftp.ne.jp
     * extras: www.ftp.ne.jp
     * updates: www.ftp.ne.jp
    Setting up Install Process
    Package 1:make-3.81-20.el6.x86_64 already installed and latest version
    Resolving Dependencies
    --> Running transaction check
    ---> Package gcc.x86_64 0:4.4.7-4.el6 will be installed
    --> Processing Dependency: cpp = 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.x86_64
    --> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.4.7-4.el6.x86_64
    ---> Package kernel-devel.x86_64 0:2.6.32-431.el6 will be installed
    ---> Package perl.x86_64 4:5.10.1-136.el6 will be installed
    --> Processing Dependency: perl-libs = 4:5.10.1-136.el6 for package: 4:perl-5.10.1-136.el6.x86_64
    --> Processing Dependency: perl-libs for package: 4:perl-5.10.1-136.el6.x86_64
    --> Processing Dependency: perl(version) for package: 4:perl-5.10.1-136.el6.x86_64
    --> Processing Dependency: perl(Pod::Simple) for package: 4:perl-5.10.1-136.el6.x86_64
    --> Processing Dependency: perl(Module::Pluggable) for package: 4:perl-5.10.1-136.el6.x86_64
    --> Processing Dependency: libperl.so()(64bit) for package: 4:perl-5.10.1-136.el6.x86_64
    --> Running transaction check
    ---> Package cpp.x86_64 0:4.4.7-4.el6 will be installed
    ---> Package glibc-devel.x86_64 0:2.12-1.132.el6_5.2 will be installed
    --> Processing Dependency: glibc-headers = 2.12-1.132.el6_5.2 for package: glibc-devel-2.12-1.132.el6_5.2.x86_64
    --> Processing Dependency: glibc = 2.12-1.132.el6_5.2 for package: glibc-devel-2.12-1.132.el6_5.2.x86_64
    --> Processing Dependency: glibc-headers for package: glibc-devel-2.12-1.132.el6_5.2.x86_64
    ---> Package perl-Module-Pluggable.x86_64 1:3.90-136.el6 will be installed
    ---> Package perl-Pod-Simple.x86_64 1:3.13-136.el6 will be installed
    --> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.13-136.el6.x86_64
    ---> Package perl-libs.x86_64 4:5.10.1-136.el6 will be installed
    ---> Package perl-version.x86_64 3:0.77-136.el6 will be installed
    --> Running transaction check
    ---> Package glibc.x86_64 0:2.12-1.132.el6 will be updated
    --> Processing Dependency: glibc = 2.12-1.132.el6 for package: glibc-common-2.12-1.132.el6.x86_64
    ---> Package glibc.x86_64 0:2.12-1.132.el6_5.2 will be an update
    ---> Package glibc-headers.x86_64 0:2.12-1.132.el6_5.2 will be installed
    --> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.12-1.132.el6_5.2.x86_64
    --> Processing Dependency: kernel-headers for package: glibc-headers-2.12-1.132.el6_5.2.x86_64
    ---> Package perl-Pod-Escapes.x86_64 1:1.04-136.el6 will be installed
    --> Running transaction check
    ---> Package glibc-common.x86_64 0:2.12-1.132.el6 will be updated
    ---> Package glibc-common.x86_64 0:2.12-1.132.el6_5.2 will be an update
    ---> Package kernel-headers.x86_64 0:2.6.32-431.20.3.el6 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package                   Arch       Version                 Repository   Size
    ================================================================================
    Installing:
     gcc                       x86_64     4.4.7-4.el6             base         10 M
     kernel-devel              x86_64     2.6.32-431.el6          base        8.7 M
     perl                      x86_64     4:5.10.1-136.el6        base         10 M
    Installing for dependencies:
     cpp                       x86_64     4.4.7-4.el6             base        3.7 M
     glibc-devel               x86_64     2.12-1.132.el6_5.2      updates     978 k
     glibc-headers             x86_64     2.12-1.132.el6_5.2      updates     608 k
     kernel-headers            x86_64     2.6.32-431.20.3.el6     updates     2.9 M
     perl-Module-Pluggable     x86_64     1:3.90-136.el6          base         40 k
     perl-Pod-Escapes          x86_64     1:1.04-136.el6          base         32 k
     perl-Pod-Simple           x86_64     1:3.13-136.el6          base        212 k
     perl-libs                 x86_64     4:5.10.1-136.el6        base        578 k
     perl-version              x86_64     3:0.77-136.el6          base         51 k
    Updating for dependencies:
     glibc                     x86_64     2.12-1.132.el6_5.2      updates     3.8 M
     glibc-common              x86_64     2.12-1.132.el6_5.2      updates      14 M
    
    Transaction Summary
    ================================================================================
    Install      12 Package(s)
    Upgrade       2 Package(s)
    
    Total download size: 56 M
    Downloading Packages:
    --------------------------------------------------------------------------------
    Total                                           5.3 MB/s |  56 MB     00:10
    warning: Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
    Importing GPG key 0xC105B9DE:
     Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
     Package: centos-release-6-5.el6.centos.11.1.x86_64 (@anaconda-CentOS-201311272149.x86_64/6.5)
     From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Updating   : glibc-common-2.12-1.132.el6_5.2.x86_64                      1/16
      Updating   : glibc-2.12-1.132.el6_5.2.x86_64                             2/16
      Installing : 1:perl-Pod-Escapes-1.04-136.el6.x86_64                      3/16
      Installing : 4:perl-libs-5.10.1-136.el6.x86_64                           4/16
      Installing : 1:perl-Pod-Simple-3.13-136.el6.x86_64                       5/16
      Installing : 3:perl-version-0.77-136.el6.x86_64                          6/16
      Installing : 1:perl-Module-Pluggable-3.90-136.el6.x86_64                 7/16
      Installing : 4:perl-5.10.1-136.el6.x86_64                                8/16
      Installing : cpp-4.4.7-4.el6.x86_64                                      9/16
      Installing : kernel-headers-2.6.32-431.20.3.el6.x86_64                  10/16
      Installing : glibc-headers-2.12-1.132.el6_5.2.x86_64                    11/16
      Installing : glibc-devel-2.12-1.132.el6_5.2.x86_64                      12/16
      Installing : gcc-4.4.7-4.el6.x86_64                                     13/16
      Installing : kernel-devel-2.6.32-431.el6.x86_64                         14/16
      Cleanup    : glibc-common-2.12-1.132.el6.x86_64                         15/16
      Cleanup    : glibc-2.12-1.132.el6.x86_64                                16/16
      Verifying  : 1:perl-Module-Pluggable-3.90-136.el6.x86_64                 1/16
      Verifying  : cpp-4.4.7-4.el6.x86_64                                      2/16
      Verifying  : kernel-headers-2.6.32-431.20.3.el6.x86_64                   3/16
      Verifying  : 4:perl-5.10.1-136.el6.x86_64                                4/16
      Verifying  : 4:perl-libs-5.10.1-136.el6.x86_64                           5/16
      Verifying  : 1:perl-Pod-Simple-3.13-136.el6.x86_64                       6/16
      Verifying  : glibc-headers-2.12-1.132.el6_5.2.x86_64                     7/16
      Verifying  : 1:perl-Pod-Escapes-1.04-136.el6.x86_64                      8/16
      Verifying  : glibc-devel-2.12-1.132.el6_5.2.x86_64                       9/16
      Verifying  : kernel-devel-2.6.32-431.el6.x86_64                         10/16
      Verifying  : gcc-4.4.7-4.el6.x86_64                                     11/16
      Verifying  : 3:perl-version-0.77-136.el6.x86_64                         12/16
      Verifying  : glibc-2.12-1.132.el6_5.2.x86_64                            13/16
      Verifying  : glibc-common-2.12-1.132.el6_5.2.x86_64                     14/16
      Verifying  : glibc-2.12-1.132.el6.x86_64                                15/16
      Verifying  : glibc-common-2.12-1.132.el6.x86_64                         16/16
    
    Installed:
      gcc.x86_64 0:4.4.7-4.el6           kernel-devel.x86_64 0:2.6.32-431.el6
      perl.x86_64 4:5.10.1-136.el6
    
    Dependency Installed:
      cpp.x86_64 0:4.4.7-4.el6
      glibc-devel.x86_64 0:2.12-1.132.el6_5.2
      glibc-headers.x86_64 0:2.12-1.132.el6_5.2
      kernel-headers.x86_64 0:2.6.32-431.20.3.el6
      perl-Module-Pluggable.x86_64 1:3.90-136.el6
      perl-Pod-Escapes.x86_64 1:1.04-136.el6
      perl-Pod-Simple.x86_64 1:3.13-136.el6
      perl-libs.x86_64 4:5.10.1-136.el6
      perl-version.x86_64 3:0.77-136.el6
    
    Dependency Updated:
      glibc.x86_64 0:2.12-1.132.el6_5.2   glibc-common.x86_64 0:2.12-1.132.el6_5.2
    
    Complete!
    Copy iso file C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
    Installing Virtualbox Guest Additions 4.3.12 - guest version is 4.3.8
    Verifying archive integrity... All good.
    Uncompressing VirtualBox 4.3.12 Guest Additions for Linux............
    VirtualBox Guest Additions installer
    Removing installed version 4.3.8 of VirtualBox Guest Additions...
    Copying additional installer modules ...
    Installing additional modules ...
    Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
    Building the VirtualBox Guest Additions kernel modules
    Building the main Guest Additions module[  OK  ]
    Building the shared folder support module[  OK  ]
    Building the OpenGL support module[  OK  ]
    Doing non-kernel setup of the Guest Additions[  OK  ]
    You should restart your guest to make sure the new modules are actually used
    
    Installing the Window System drivers
    Could not find the X.Org or XFree86 Window System, skipping.
    An error occurred during installation of VirtualBox Guest Additions 4.3.12. Some functionality may not work as intended.
    In most cases it is OK that the "Window System drivers" installation failed.
    ==> default: Checking for guest additions in VM...
    ==> default: Mounting shared folders...
        default: /vagrant => D:/HOME/punio/vagrant
    

    Boxを起動すると、システム更新とVirtualBox Quest Add-inの更新が行われますが、Guest Add-inの更新は、Vagrantプラグインのvagrant-vbguestをインストールしているためですので、このプラグインをインストールしていないVagrant環境では、Guest Add-inの更新は行われません。

    以上で、Vagrant Cloud上のBoxが利用可能になりました。