Tbpgr Blog

Recruiting Operations tbpgr(てぃーびー) のブログ

Vagrant | 複数環境の一括構築

概要

複数環境の一括構築

詳細

複数環境の一括構築

手順

$ mkdir multi_vagrant
$ cd multi_vagrant
$ vagrant init
# => 編集内容の詳細は後述
$ vi Vagrantfile

# VM起動。※denreiは自作のgemで実行完了時にダイアログを表示するだけです。
$ vagrant up;denrei
Bringing machine 'one' up with 'virtualbox' provider...
Bringing machine 'other' up with 'virtualbox' provider...
[one] Importing base box 'ubuntu-12.04-x64'...
 :
 : # 中略
 :
   ___  _ __   ___   _ __  _ __ _____   _(_)___(_) ___  _ __
  / _ \| '_ \ / _ \ | '_ \| '__/ _ \ \ / / / __| |/ _ \| '_ \
 | (_) | | | |  __/ | |_) | | | (_) \ V /| \__ \ | (_) | | | |
  \___/|_| |_|\___| | .__/|_|  \___/ \_/ |_|___/_|\___/|_| |_|
                    |_|
                                  _
  ___ _   _  ___ ___ ___  ___ ___| |
 / __| | | |/ __/ __/ _ \/ __/ __| |
 \__ \ |_| | (_| (_|  __/\__ \__ \_|
 |___/\__,_|\___\___\___||___/___(_)
 :
 : # 1VM目起動完了
 :
 : # 中略
 :
        _   _                                      _     _
   ___ | |_| |__   ___ _ __   _ __  _ __ _____   _(_)___(_) ___  _ __
  / _ \| __| '_ \ / _ \ '__| | '_ \| '__/ _ \ \ / / / __| |/ _ \| '_ \
 | (_) | |_| | | |  __/ |    | |_) | | | (_) \ V /| \__ \ | (_) | | | |
  \___/ \__|_| |_|\___|_|    | .__/|_|  \___/ \_/ |_|___/_|\___/|_| |_|
                             |_|
                                  _
  ___ _   _  ___ ___ ___  ___ ___| |
 / __| | | |/ __/ __/ _ \/ __/ __| |
 \__ \ |_| | (_| (_|  __/\__ \__ \_|
 |___/\__,_|\___\___\___||___/___(_)

# VMを確認
$ vagrant status
Current machine states:

one                       running (virtualbox)
other                     running (virtualbox)

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.
$ vagrant status one
Current machine states:

one                       running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

$ vagrant status other
Current machine states:

other                     running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

$ vagrant ssh one
$ git version
git version 1.7.9.5
$ exit

$ vagrant ssh other
$ which tree
/usr/bin/tree
$ exit

$ vagrant destroy

Vagrantfile

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu-12.04-x64"

  config.vm.define "one" do |one|
    # one.vm.name = "one"
    config.vm.provision "shell", inline: <<-EOS
sudo apt-get install git -y
sudo apt-get install figlet -y
figlet 'one provision success!'
    EOS
  end
  config.vm.define "other" do |other|
    # other.vm.name = "other"
    config.vm.provision "shell", inline: <<-EOS
sudo apt-get install tree -y
sudo apt-get install figlet -y
figlet 'other provision success!'
    EOS
  end
end