8
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 3 years have passed since last update.

VagrantでVMwareをproviderにして環境構築する【Windows】

Last updated at Posted at 2020-09-13

はじめに

VagrantのproviderとしてVirtualBoxを利用するケース・情報は多数ありますが、VMwareについては情報が少ないのでまとめてみました。
もともと、Hyper-Vを有効にした環境でVirtualBoxを利用したかったのですが、安定して動かないため、VMwareを利用することにしました。

※2021/1/13追記:
VMwareのバージョンが新しくなり、また価格も値下がりしたので更新しました。本稿作成時、VMware Workstationはバージョン15でしたが、現時点の最新版はバージョン16となっています。また、VMware Workstation Player/Proの価格はそれぞれ $149 および $199 となっています。

やりたかったこと

  • Vagrantにて、VirtualBoxを利用した場合と同等の利便性を実現する
    • ゲストOSのIPアドレスを固定する
    • ゲスト/ホスト間でファイル共有する(synced_folder)

TL;DR

  • VagrantでVMwareをproviderにする場合、Vagrant VMware Utility、Vagrant VMware pluginのインストールが必要
  • Vagrant VMware pluginは有償ライセンスが必要($79)
  • VMware自体も有償ライセンスが必要($149 or $199)(※VMware Workstation Player/Pro 16の場合)

環境

  • OS: Microsoft Windows 10 Pro 10.0.19041 Build 19041
  • CPU: Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz, 3401 Mhz, 4 Core(s), 8 Logical Processor(s)
  • GitBash: 2.27.0
  • Vagrant: 2.2.10
  • VMware Workstation Pro: 15.5.6 build-16341506

作業概要

  • VMware Workstation Pro/Playerの有償版を購入する・インストールする
  • Vagrantのセットアップ
    • Vagrantをインストールする
    • Vagrant VMware pluginを購入する
    • Vagrant VMware pluginにライセンスファイルをインストールする
  • 仮想サーバのセットアップ
    • Vagrantfileを作成する
    • vagrant up!

作業詳細

VMware Workstation Pro/Playerの有償版を購入する・インストールする

VMwareのサイトから、VMware Workstation Pro/Playerのいずれかをダウンロードしてインストールします。

https://www.vmware.com/products/workstation-pro.html
https://www.vmware.com/products/workstation-player.html

インストール後、ライセンスを購入します。
30日のトライアル/非商用での利用を選択した場合、後述しますが、vagrant up時にエラーメッセージが出力され、動きません。

Vagrantのセットアップ

基本的に、下記公式ドキュメント記載のとおりです。
https://www.vagrantup.com/docs/providers/vmware/installation

本稿では、ハマりやすいポイント、具体的なエラーメッセージを併せて書きます。

Vagrantをインストールする

下記からダウンロードしてインストールします。特にハマりやすい点は無いと思います。

Vagrant VMware Utilityをインストールする

下記URLから、Vagrant VMware Utilityをダウンロードしてインストールします。
こちらも指示に従うだけなので、特に問題は起きないと思います。

Vagrant VMware pluginをインストールする

GitBashから以下のコマンドを実行し、Vagrant VMware pluginをインストールします。

$ vagrant plugin install vagrant-vmware-desktop

Vagrant VMware pluginを購入する

下記にある通り、Vagrant VMware pluginは商用プロダクトなので、ライセンスの購入が必要です。
2020/9/13現在、$79です。

The Vagrant VMware plugin is a commercial product provided by HashiCorp and require the purchase of a license to operate. To purchase a license, please visit the Vagrant VMware provider page.

Installation - VMware Provider | Vagrant by HashiCorp
https://www.vagrantup.com/docs/providers/vmware/installation#installation

Vagrant VMware pluginにライセンスファイルをインストールする

ライセンスを購入したら、ライセンスファイルをダウンロードします。
以下のコマンドで、Vagrant VMware pluginのライセンスファイルをインストールします。

$ vagrant plugin license vagrant-vmware-desktop /path/to/license.lic

なお、ドキュメントにも以下の注意書きがありますが、VMware自体のライセンスファイルはVagrant VMware pluginには適用できません。

Warning! You cannot use your VMware product license as a Vagrant VMware plugin license. They are separate commercial products, each requiring their own license.

vagrantコマンドのみを実行して、ライセンスに関するエラーメッセージが出力されなければ、Vagrantのセットアップは完了です。

$ vagrant

ゲストOS(Vagrantfile)のセットアップ

VMware providerの位置づけ・注意点

VMware providerは、VirtualBox providerと同じように使えるよう設計されているようです。しかしながら、幾つか差異があるので注意が必要です。

This provider is a drop-in replacement for VirtualBox. However, there are some VMware-specific things such as box formats, configurations, etc. that are documented here.

VMware Provider | Vagrant by HashiCorp
https://www.vagrantup.com/docs/providers/vmware

Vagrantfileを作成する

Vagrant Boxは "bento/ubuntu-20.04" を利用します。
IPアドレスを指定し、またsynced_folderを利用します。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "bento/ubuntu-20.04"
 
  config.vm.provider "vmware_desktop" do |v|
    v.memory = 1024
    v.cpus = 1
  end

  config.vm.define :"stdsv7" do |c1|
    c1.vm.hostname = "stdsv7"
    c1.vm.network "private_network",ip: "192.168.254.15"
  end

  config.vm.synced_folder "../", "/home/vagrant/local_workspace" , type: "smb"
end

なお、synced_folderのプロトコルはSMBを利用することとなります。VirtualBoxではないので、vboxsfが利用できないからです。
後述しますが、synced_folderでSMBを利用する場合、vagrant up時にフォルダ共有を行う権限のあるユーザ名・パスワードを聞かれます。

SMB - Synced Folders | Vagrant by HashiCorp
https://www.vagrantup.com/docs/synced-folders/smb

vagrant up!

GitBashからwinptyを利用してvagrant upを実行します。
ここで、VMwareのライセンスが商用のものでない場合、エラーが出力されます。(後述)

起動中に、共有フォルダを設定することができるアカウントのユーザ名・パスワードを聞かれますが、winptyを利用しない場合、パスワードがコンソールにそのまま表示されてしまいますので注意してください。

このアカウントは、通常、Windowsにログオンしている作業用のアカウントと同じでOKです。(大体、Administrators権限を付与していると思いますので)

ゲストOSが起動すること、IPアドレスが指定のものになっていることを確認します。

$ winpty vagrant up
==> stdsv7: Stopping the VMware VM...
==> stdsv7: Deleting the VM...

Vagrant requires administrator access for pruning SMB shares and
may request access to complete removal of stale shares.
Bringing machine 'stdsv7' up with 'vmware_desktop' provider...
==> stdsv7: Cloning VMware VM: 'bento/ubuntu-20.04'. This can take some time...
==> stdsv7: Checking if box 'bento/ubuntu-20.04' version '202008.16.0' is up to date...
==> stdsv7: Verifying vmnet devices are healthy...
==> stdsv7: Preparing SMB shared folders...
    stdsv7: You will be asked for the username and password to use for the SMB
    stdsv7: folders shortly. Please use the proper username/password of your
    stdsv7: account.
    stdsv7:
    stdsv7: Username (user[@domain]): yourname
    stdsv7: Password (will be hidden):

Vagrant requires administrator access to create SMB shares and
may request access to complete setup of configured shares.
==> stdsv7: Preparing network adapters...
==> stdsv7: Starting the VMware VM...
==> stdsv7: Waiting for the VM to receive an address...
==> stdsv7: Forwarding ports...
    stdsv7: -- 22 => 2222
==> stdsv7: Waiting for machine to boot. This may take a few minutes...
    stdsv7: SSH address: 127.0.0.1:2222
    stdsv7: SSH username: vagrant
    stdsv7: SSH auth method: private key
    stdsv7: Warning: Remote connection disconnect. Retrying...
    stdsv7:
    stdsv7: Vagrant insecure key detected. Vagrant will automatically replace
    stdsv7: this with a newly generated keypair for better security.
    stdsv7:
    stdsv7: Inserting generated public key within guest...
    stdsv7: Removing insecure key from the guest if it's present...
    stdsv7: Key inserted! Disconnecting and reconnecting using new SSH key...
==> stdsv7: Machine booted and ready!
==> stdsv7: Setting hostname...
==> stdsv7: Configuring network adapters within the VM...
==> stdsv7: Mounting SMB shared folders...
    stdsv7: D:/Dev/git/server-config => /home/vagrant/local_workspace
    stdsv7: D:/Dev/git => /home/vagrant/projects
==> stdsv7: Waiting for HGFS to become available...
==> stdsv7: Enabling and configuring shared folders...
    stdsv7: -- D:/Dev/git/server-config/vagrant_ubuntu20_vmware: /vagrant
==> stdsv7: Running provisioner: shell...
    stdsv7: Running: C:/Users/yourname/AppData/Local/Temp/vagrant-shell20200913-9692-7ydmf7.sh
    stdsv7: WARNING:
※途中省略
$ vagrant ssh
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-42-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun 13 Sep 2020 01:33:47 AM UTC

  System load:  0.05              Processes:             144
  Usage of /:   2.4% of 61.31GB   Users logged in:       0
  Memory usage: 18%               IPv4 address for eth0: 192.168.254.129
  Swap usage:   0%                IPv4 address for eth1: 192.168.254.16


0 updates can be installed immediately.
0 of these updates are security updates.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


This system is built by the Bento project by Chef Software
More information can be found at https://github.com/chef/bento
vagrant@stdsv7:~$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:42:04:11 brd ff:ff:ff:ff:ff:ff
    inet 192.168.254.128/24 brd 192.168.254.255 scope global dynamic eth0
       valid_lft 1636sec preferred_lft 1636sec
    inet6 fe80::20c:29ff:fe42:411/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:42:04:1b brd ff:ff:ff:ff:ff:ff
    inet 192.168.254.15/24 brd 192.168.254.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe42:41b/64 scope link
       valid_lft forever preferred_lft forever

よくあるエラー

VMwareのライセンスが非商用の場合

VMware Workstation Pro/Playerを、30日間の評価ライセンス/非営利目的での利用として利用している場合、vagrant up時に以下のエラーが出力されます。

$ vagrant up
Vagrant encountered an error while attempting to inspect VMware
for current version information:

  The system cannot find the file specified.

FAQにも以下の記載があります。trial versionにしか言及がありませんが、どうも非営利目的での利用の場合も同様のようです。

Q: Why is the Vagrant VMware plugin not working with my trial version of VMware Fusion/Workstation?

The Vagrant VMware Fusion and Vagrant VMware Workstation plugins are not compatible with trial versions of the VMware products. We apologize for the inconvenience.

Installation - VMware Provider | Vagrant by HashiCorp
https://www.vagrantup.com/docs/providers/vmware/installation#frequently-asked-questions

Vagrant VMware Utilityをインストールしていない

ドキュメントを読み飛ばして、Vagrant VMware Utilityをインストールしない状態で作業を進めると、vagrant up時に以下のエラーが出力されます。
指示通り、Vagrant VMware Utilityをインストールする必要があります。

$ vagrant up
Vagrant encountered an error while attempting to load the utility
service key file. This error can occur if the Vagrant VMware Utility
has not yet been installed, or if it was installed incorrectly. If
this error persists after running the Vagrant VMware Utility installer
again, please contact support at: support@hashicorp.com

Information about the Vagrant VMware Utility, including installation
instruction, can be found here:

  https://www.vagrantup.com/docs/vmware/vagrant-vmware-utility.html

  Path:  C:/ProgramData/hashicorp/vagrant-vmware-desktop/certificates/vagrant-utility.client.crt
  Error: No such file or directory @ rb_sysopen - C:/ProgramData/hashicorp/vagrant-vmware-desktop/certificates/vagrant-utility.client.crt

指定したIPアドレスレンジがVirtualBoxで利用しているものと被ってしまう

VMWWareやVirtualBoxは、仮想ネットワークを作り、またホストOS用であるWindowsに仮想NICを作ります。このネットワークアドレスが被ってしまうと、下記のようにエラーが出力されます。

$ vagrant up
Bringing machine 'stdsv7' up with 'vmware_desktop' provider...
==> stdsv7: Cloning VMware VM: 'bento/ubuntu-20.04'. This can take some time...
==> stdsv7: Checking if box 'bento/ubuntu-20.04' version '202008.16.0' is up to date...
==> stdsv7: Verifying vmnet devices are healthy...
The host only network with the IP '192.168.255.15' would collide with
another device 'VirtualBox Host-Only Network #2'. This means that VMware cannot create
a proper networking device to route to your VM. Please choose
another IP or shut down the existing device.

おわりに

VagrantでVMwareを利用する場合、ライセンスの購入が必要となるため、本記事の需要は少ない気がしますが、記録として残しておきます。

8
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
8
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?