Vagrantコマンドのメモ

# よく使うコマンドの一覧

|   Command   |     説明     |
|-------------|--------------|
| vagrant box add | boxを追加 |
| vagrant init | 初期化 |
| vagrant up | 仮想マシンをprovisioning |
| VAGRANT_LOG=info vagrant up | デバッグ | 
| vagrant up --provider=softlayer | プロバイダを指定して仮想マシンを起動 | 
| vagrant ssh | sshで仮想マシンに接続 |
| vagrant provision | chefなどでのprovisioningを実行 |
| vagrant rsync | sync folderのデータを同期 |
| vagrant suspend | 停止 |
| vagrant resume | 再開 |
| vagrant destroy | 仮想マシンを削除。確認を求められる。 |
| vagrant destroy -f | 仮想マシンを確認なしで強制的に削除 |
| vagrant plugin list | インストールされているプラグインを表示 |
| vagrant plugin install softlayer | プラグインのインストール |
| vagrant plugin update softlayer | プラグインの更新|


# 準備

## vagrant box

```bash:Syntax
$ vagrant box add {title} {url}
```
```bash:実行例
$ vagrant box add centos64 http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20131103.box
==> box: Adding box 'centos64' (v0) for provider:
    box: Downloading: http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20131103.box
    box:
==> box: Successfully added box 'centos64' (v0) for 'virtualbox'!
```

Boxファイルは以下に保存される

Windows & VirtualBoxの場合: ```C:\Users\<User>\VirtualBox VMs\CentOS-6.4-x86_64```
Linux/Macの場合: 


## vagrant init

```bash:実行例
$ vagant init
```


# 起動

## vagrant up

```bash:Syntax
$ vagrant up [options] [name]
```

```bash:Windows+VirtualBoxでの実行例
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos64'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vagrant_default_1405910855448_31496
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> 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: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => C:/cygwin/home/Takechika/vagrant
http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20131103.box
vagrant/vagrant
root/vagrant
```


```bash:Providerの指定
$ vagrant up --provider=softlayer
```


# 操作

## vagrant provision

```bash:実行例
$ vagant provision
```

## vagrant rsync

```bash:実行例
$ vagant rsync
```

## vagrant ssh

```bash:実行例
[osx]$ vagrant ssh
Last login: Thu Jan  1 15:10:18 2015 from 10.0.2.2
[vagrant@docker-centos7 ~]$ hostname
docker-centos7
[vagrant@docker-centos7 ~]$ exit
logout
Connection to 127.0.0.1 closed.
```



## vagrant suspend

```bash:実行例
$ vagant suspend
```


## vagrant resume

```bash:実行例
$ vagant resume
```


## vagrant destroy

```bash:実行例
$ vagrant destroy

    default: Are you sure you want to destroy the 'default' VM? [y/N]  y

==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
```


```bash:実行例
$ vagrant destroy -f
```



# プラグイン

## vagrant plugin list

```bash:実行例
$ vagrant plugin list
vagrant-aws (0.6.0)
vagrant-login (1.0.1, system)
vagrant-omnibus (1.4.1)
vagrant-share (1.1.4, system)
vagrant-softlayer (0.4.0)
```


## vagrant plugin install

```bash:実行例
$ sudo vagrant plugin install vagrant-softlayer
Installing the 'vagrant-softlayer' plugin. This can take a few minutes...
Installed the plugin 'vagrant-softlayer (0.4.0)'!
```

## vagrant plugin update

```bash:実行例
$ sudo vagrant plugin update vagrant-softlayer
Updating plugins: vagrant-softlayer. This may take a few minutes...
All plugins are up to date.
```




# デバック

```bash:実行例
$ VAGRANT_LOG=info vagrant up
```