LoginSignup
13
13

More than 1 year has passed since last update.

ChefもKnifeも知らない初心者がBerkshelfに頼ってVagrantでUbuntuを構築する例

Last updated at Posted at 2013-07-11

はじめに

調理の初心者がBerkshelfに頼ってVagrantのVMを構築します.Ubuntuを動かし,試しにgitをインストールしてみます.なお,RubyやVagrant本体は既にインストールしてあるものとします.この記事執筆時点でのバージョンです.

  • VirtualBox 4.2.16 for Linux
  • Vagrant 1.2.3
  • ruby 2.0.0p195

なお,rbenvには

  • ruby-build
  • rbenv-binstubs

のプラグインを入れています.

インストール

berkshelfとvagrant用プラグインをインストールします.

$ gem install berkshelf
$ vagrant plugin install vagrant-berkshelf
Installing the 'vagrant-berkshelf' plugin. This can take a few minutes...
Installed the plugin 'vagrant-berkshelf (1.3.2)'!

berksで初期化

「precise」という名前で作成します.

$ berks cookbook precise
      create  precise/files/default
      create  precise/templates/default
      create  precise/attributes
      (省略)
         run  git init from "./precise"
      create  precise/Gemfile
      create  precise/Vagrantfile

できたディレクトリに移動して,記録のためにcommitしておきます.

$ cd precise
$ git add .
$ git commit -a -m 'Initial commit'

bundle install

さらにbundleinstallとかもやっておきます.このフォルダで入力したコマンドはbundleexecなしでもこの場所でインストールされたバージョンのものになります(rbenvにrbenv-binstubsプラグインを入れてあるので).

$ bundle install --path=vendor/bundle --binstubs=vendor/bin
$ bundle package --all
$ echo 'vendor/bundle' >> .gitignore
$ git add .
$ git commit -a -m 'Bundle install'

vendor/bundleにgemが,vendor/cacheにダウンロードしてきたgemが,vendor/binに実行コマンドインストールされます.vundle/bulder以外はgitの管理下に置きます.なお,この手順を省略し,Bundle外の共通のgemとしてbundleinstallしても構いません.

Vagrantfileの変更

ツールが生成したVagrantfileはCentOSになっているのでUbuntuに変更します.

$ vim Vagrantfile

変更した内容は次のとおりです.

diff --git a/Vagrantfile b/Vagrantfile
index f7e6e9f..efdbb32 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -6,14 +6,14 @@ Vagrant.configure("2") do |config|
   # options are documented and commented below. For a complete reference,
   # please see the online documentation at vagrantup.com.

-  config.vm.hostname = "precise-berkshelf"
+  config.vm.hostname = "precise"

   # Every Vagrant virtual environment requires a box to build off of.
-  config.vm.box = "Berkshelf-CentOS-6.3-x86_64-minimal"
+  config.vm.box = "precise"

   # The url from where the 'config.vm.box' box will be fetched if it
   # doesn't already exist on the user's system.
-  config.vm.box_url = "https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box"
+  config.vm.box_url = "http://files.vagrantup.com/precise32.box"

   # Assign this VM to a host-only network IP, allowing you to access it
   # via the IP. Host-only networks can talk to the host machine as well as

Vagrantを立ち上げる

起動させてみます.

$ vagrant up
$ vagrant ssh

きちんとログインできました.

Berksfileの編集

試しにgitを追加してみます.Berksfileをエディタで開きます.

$ vim Berksfile

変更内容は次の通り.

diff --git a/Berksfile b/Berksfile
index c4bb297..6d86dcf 100644
--- a/Berksfile
+++ b/Berksfile
@@ -1,3 +1,4 @@
 site :opscode

 metadata
+cookbook 'git'

Vagrantfileの編集

Vagrantfileも変更します.

$ vim Vagrantfile

こちらは,次のように変更しました.

diff --git a/Vagrantfile b/Vagrantfile
index efdbb32..dbb240a 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -80,7 +80,8 @@ Vagrant.configure("2") do |config|
     }

     chef.run_list = [
-        "recipe[precise::default]"
+        "recipe[precise::default]",
+        "git"
     ]
   end
 end

再起動

$ vagrant reload

sshして試すと,無事,gitが使えるようになっています.

感想

ChefやKnifeはいずこへ・・・笑

おわりに

この記事はVagrant初心者が書いておりますので,もし間違い等ございましたらご遠慮なく連絡ください♪

次回はrbenvでrubyの環境を構築する例を紹介します.


  • source /mnt/c/Users/yc/Dropbox/org/qiita/8c57481b85865e562c47.org
13
13
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
13
13