備忘録『Ansible構築・運用ガイドブック インフラ自動化のための現場のノウハウ』のハマった所 3章


"3-2-2 Vagrant Box を起動"でハマった

VirtualBox ,Vagrant の環境構築でハマったため、備忘録として残します。

要約

  • 2019/12/15 最新版の Vagrant 2.2.6 は 最新版の VirtualBox 6.1 を扱えません。
  • Vagrant の扱える仮想化基盤のバージョンを利用しましょう。(今回はVirtualBox 6.0)
  • Vagrant の扱る仮想基盤のバージョンってどこに記載されているか誰か教えてください。。。

はじめに

3章では、Windows 上に VirtualBox と Vagrant の最新版をインストールします。
登場するソフトウェアとバージョンは以下の通りです。

  • 環境
    • Windows10 Pro (64bit) バージョン1903(OS ビルド 18362.476)
    • VirtualBox Vesion 6.1.0r135406(Qt5.6.2)
    • Vagrant 2.2.6

1度目の Vagrantfile の作成と起動

指定された Vagrantfile を作成します。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.network "private_network", ip: "192.168.33.10"

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "1024"
  end  
end

個人的な感想にりますが、vagrant init コマンドを利用したほうが良い気がします。
vagrant init を実行すると Vagrantfile の雛形が作られ typo しにくくなります。
私は書籍を見ながら書きましたが、typo しやすく、構文エラーと格闘することになりました。

仮想マシンの起動コマンドを実行した結果は以下の通りです。

実行結果1
> vagrant up
No usable default provider could be found for your system.

Vagrant relies on interactions with 3rd party systems, known as        
"providers", to provide Vagrant with resources to run development      
environments. Examples are VirtualBox, VMware, Hyper-V.

The easiest solution to this message is to install VirtualBox, which   
is available for free on all major platforms.

If you believe you already have a provider available, make sure it     
is properly installed and configured. You can see more details about   
why a particular provider isn't working by forcing usage with
`vagrant up --provider=PROVIDER`, which should give you a more specific
error message for that particular provider.

仮想化基盤のプロバイダがないからコマンドで指定してほしいと表示されました。

2度目のコマンドの実行

仮想化基盤のプロバイダを指定し、再度、仮想マシンの起動コマンドを実行します。

実行結果2
> vagrant up --provider=virtualbox
The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The
reason is shown below:

Vagrant has detected that you have a version of VirtualBox installed
that is not supported by this version of Vagrant. Please install one of
the supported versions listed below to use Vagrant:

4.0, 4.1, 4.2, 4.3, 5.0, 5.1, 5.2, 6.0

A Vagrant update may also be available that adds support for the version
you specified. Please check www.vagrantup.com/downloads.html to download
the latest version.

VirtualBox のバージョンは 4.0, 4.1, 4.2, 4.3, 5.0, 5.1, 5.2, 6.0 のみを受け付けると表示されました。
2019/12/15 段階の Vagrant の最新版は、 VirtualBox 6.1 を受け付けてくれないようです。

3度目の正直(う、動いてくれ)

VirtualBox 6.1 をアンインストールし、VirtualBox 6.0.14 をインストールしました。
インストール完了後、仮想マシンの起動コマンドをオプションなしで実行します。

> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
(中略)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
(中略)
==> default: Machine booted and ready!
(中略)
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /cygdrive/c/Users/deep_/GitHub/ansible_playbooks/chapter3/ => /vagrant
>

う、うごいたーーーー。

動いたみたいです。
念のため、起動中の仮想マシンを確認するコマンドを実行します。

> vagrant global-status
id       name    provider   state   directory
-------------------------------------------------------------------------------------
7a62c76  default virtualbox running C:/Users/XXXXXX/ansible_playbooks/chapter3

ばっちり動いていました。

終わりに

Vagrant が扱える仮想化基盤のバージョンにすることで動きました。しかしながら、どの仮想化基盤のバージョンであれば、Vagrant が扱えるのかドキュメントが見当たりませんでした。
どなたか知っている人がいれば教えてください。