4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vagrant | version 1.5 新規フィーチャー #vagrant

Posted at

Vagrant | version 1.5 新規フィーチャー #vagrant

概要

Vagrant の version 1.5 で新規追加されたフィーチャーについて

(2014/11/20 時点で Vagrant の最新バージョンは 1.6.5 なので「いまさら」な内容ではありますが。)

Major Features

Vagrant Share

Vagrant Share

簡単なコマンドでローカルの Vagrant 環境を世界中の誰とでもシェアできる。
Vagrant Cloud の登録が必要だが無料枠あり

vagrant share

  • HTTP Sharing

デフォルトでは、 vagrant share は、 HTTP へのアクセスをシェアする。
実行すると一意な URL が割り振られ、外部の誰でもアクセスが可能になります。
(当然、外部からアクセスする人は Vagrant 不要)

  • SSH Access

--ssh option とともに vagrant share を呼び出すと、 ssh 接続を共有できる。
例えば、うまく動かないプログラムをペアプログラミングする、などの用途に使える。
接続側は vagrant connect を利用する。

共通鍵と暗号化パスワードは手動で相手に伝える。(セキュリティのため)

vagrant connect

下記の呼び出しにより、まるでローカルネットワーク上にあるかのように
Vagrant の VM にアクセスできる。

$ vagrant connect SHARE-NAME

Boxes 2.0

Vagrant 1.5 では、 Box の検索・ダウンロード・利用システムを変更した。
これにより、

  • 見つけやすく
  • ビルドしやすく
  • 使いやすく
  • 更新しやすく

なった。

Box はコミュニティの貢献などにより、 Box はどんどんと増えて来たが、
増えて来たが上に Box を見つけることや共有はだんだんと難しくなってきた。

Vagrant 1.5 のリリースとともに、 Box をみつけ、共有するためのWeb サイト = Vagrant Cloud をラウンチした。
このサイトでは、各 Box の

  • short name
  • バージョン
  • 複数プロバイダ
  • 変更履歴

などをサポートします。
Box は必ずしも物理的にホストするようはない。
Box は Private なネットワークないで管理したければ
メタ情報のみを登録すればよい。
また、特定の人のみが利用可能な Private Box の設定をすることも可能です。

Box Shortnames

Vagrant 1.5 以前は、 Box に short name と URL のみの情報を持っていた。
short name は config.vm.box に設定する際の名前です。

# vagrant box add <short name> <url>
$ vagrant box add precise64 http://files.vagrantup.com/precise64.box 

Vagrant 1.5 以降は、 下記のような形式になっています。

# vagrant box add <account/short name>
vagrant box add hashicorp/precise64

また、この Box は複数プロバイダをサポートしているため, add 時に
下記のような選択メニューが表示されます。

$ vagrant box add hashicorp/precise64
==> box: Loading metadata for box 'hashicorp/precise64'
    box: URL: https://vagrantcloud.com/hashicorp/precise64
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) hyperv
2) virtualbox
3) vmware_fusion

Enter your choice: 2
==> box: Adding box 'hashicorp/precise64' (v1.1.0) for provider: virtualbox
    box: Downloading: https://vagrantcloud.com/hashicorp/boxes/precise64/versions/2/providers/virtualbox.box
    box:
==> box: Successfully added box 'hashicorp/precise64' (v1.1.0) for 'virtualbox'

$ vagrant box list
hashicorp/precise64         (virtualbox, 1.1.0)

# Vagarnt 1.4 以前に取得した Box はバージョン情報がない
precise32                   (virtualbox, 0)
precise64                   (virtualbox, 0)

※上記の Box 情報は下記URL にて確認可能
https://vagrantcloud.com/hashicorp/boxes/precise64

下位互換のため、今までの short name + URL 形式による BOX の追加もそのまま利用できます。

Box Versions

多くの要望が寄せられていた、 Box のバージョン管理を実現した。
以前は、 Box の更新通知・更新内容の詳細・いくつの更新があるのか、
などを伝える方法がありませんでした。

Vagrant 1.5 では Box はバージョンを持っています。
Vagrantfiles は Box のバージョン番号を含めて設定できます。

  • Box の追加
    デフォルトでは、最新の Box を取得します
# 2014/11/20 時点だと version 1.1.0 を取得
$ vagrant box add hashicorp/precise64

オプション指定で追加する場合は、 --box-version VERSION を利用します

$ vagrant box add hashicorp/precise64 --box-version "1.0.0"
  • Box の使用
Vagrantfile
# 略
  config.vm.box = "hashicorp/precise64"
  config.vm.box_version = ">= 1.2.0, < 2.0.0"
# 略

Box Updates

Box が古くなっているかどうか確認するには二つの方法があります。

  • vagrant box outdated
$ vagrant global-status
id       name    provider   state   directory                                   
---------------------------------------------------------------------------------------
47f9788  default virtualbox running /path/to/your/dir/20141119_vagrant_1_6/docker
8a8d531  default virtualbox running /path/to/your/dir/20141120_vagrant_1_5/test

$ vagrant box outdated 8a8d531
/path/to/your/dir/test/Vagrantfile:5: warning: already initialized constant VAGRANTFILE_API_VERSION
/path/to/your/dir/test/Vagrantfile:5: warning: previous definition of VAGRANTFILE_API_VERSION was here
Checking if box 'hashicorp/precise64' is up to date...
A newer version of the box 'hashicorp/precise64' is available! You currently
have version '1.0.0'. The latest is version '1.1.0'. Run
`vagrant box update` to update.
  • vagrant up

vagrant up は実行時に、利用 Box が古ければ警告を出してくれます。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/precise64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: A newer version of the box 'hashicorp/precise64' is available! You currently
==> default: have version '1.0.0'. The latest is version '1.1.0'. Run
# 略

Box を更新する場合は

$ vagrant box list | grep hashi
hashicorp/precise64         (virtualbox, 1.0.0)
$ vagrant box update
==> default: Checking for updates to 'hashicorp/precise64'
    default: Latest installed version: 1.0.0
    default: Version constraints:
    default: Provider: virtualbox
==> default: Updating 'hashicorp/precise64' with provider 'virtualbox' from version
==> default: '1.0.0' to '1.1.0'...
==> default: Loading metadata for box 'https://vagrantcloud.com/hashicorp/precise64'
==> default: Adding box 'hashicorp/precise64' (v1.1.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/hashicorp/boxes/precise64/versions/2/providers/virtualbox.box
    default:
==> default: Successfully added box 'hashicorp/precise64' (v1.1.0) for 'virtualbox'!
$ vagrant box list | grep hashi
hashicorp/precise64         (virtualbox, 1.0.0)
hashicorp/precise64         (virtualbox, 1.1.0)

を利用します。

Rsync Synced Folders

Rsync Synced Folders

rsync の利用

synced_folder の type を "rsync" に設定します。

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

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.synced_folder ".", "/vagrant", type: "rsync"
end

Vagrant は vagrant up , vagrant reload 時に設定したフォルダを同期します。

$ vagrant up
$ vagrant ssh
vagrant@precise64:~$ cd /vagrant/
# 同期によって Vagrantfile があることを確認
vagrant@precise64:/vagrant$ ls
Vagrantfile
vagrant@precise64:/vagrant$ exit
$ echo hoge > hoge.txt
$ vagrant ssh
vagrant@precise64:~$ cd /vagrant/
# hoge.txt が同期されたか確認するが同期されていない
vagrant@precise64:/vagrant$ ls -F | grep hoge
vagrant@precise64:/vagrant$ exit
$ vagrant rsync
==> default: Rsyncing folder: /path/to/your/dir/ => /vagrant
$ vagrant ssh
vagrant@precise64:~$ cd /vagrant/
# hoge.txt が同期されたか確認。同期された。
vagrant@precise64:/vagrant$ ls -F | grep hoge
hoge.txt
vagrant@precise64:/vagrant$ cat hoge.txt
hoge

自動同期設定

  • rsync-auto コマンドを利用して自動同期設定をします
$ vagrant rsync-auto
$ echo test_auto > test_auto.txt
$ vagrant ssh
vagrant@precise64:~$ cd /vagrant/
vagrant@precise64:/vagrant$ ls -F | grep auto
test_auto.txt

Hyper-V

Hyper-V

Hyper V プロバイダに対応。

SMB Synced Folders

SMB Synced Folders

Windows 向けのフォルダ同期サポートのため SMB Synced Folders を導入。

参照

Vagrant blog
Vagrant Cloud
Vagrant Cloud | Pricing

4
5
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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?