LoginSignup
10
9

More than 5 years have passed since last update.

Vagrantfileでeachを使ってVMを量産する

Posted at

Vagrant 環境で複数のVMが必要なとき、自分はこれまで Vagrantfile に config.vm.define ブロックを VM の台数分記述していました。ところが Vagrantfile 内で each を使ってループを記述することができるそうです。試してみました。

host100からhost110まで作る
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  (100..110).each do |i|
    config.vm.define "host#{i}" do |host|
      host.vm.hostname = "host#{i}"
      host.vm.network :private_network, ip: "192.168.0.#{i}"
      host.vm.network :forwarded_port, guest: 22, host: i*100+22, id: "ssh"
    end
  end
end

おおぉ、こりゃ楽チン。

参考

10
9
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
10
9