Wednesday 2 July 2014

Vagrantfile multi-instance config exmaple

Few Vagrantfile config examples:


NOTE1:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Every Vagrant virtual environment requires a box to build off of.
  config.vm.box = "my_vagrant_image"


## NOTE: You can set the private ip of your vagrant box.

  # using a specific IP.
  config.vm.network :private_network, ip: "10.0.0.2"  # 0.1 is not a good idea.


 end

NOTE2:
Running multiple instance:

https://docs.vagrantup.com/v2/multi-machine/index.html

Note: In the following example we can have two instance running at the same time.

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.define "web" do |web|
    web.vm.box = "my_vagrant_image"
    web.vm.network :private_network, ip: "10.0.0.2"
  end

  config.vm.define "db" do |db|
    db.vm.box = "my_vagrant_image"
    db.vm.network :private_network, ip: "10.0.0.3"
  end

  config.vm.define "vg4" do |vg4|
    vg4.vm.box = "my_vagrant_image.box"
    vg4.vm.network :private_network, ip: "10.0.0.4"
  end

end



## Note there a private key, you can use:
~/.vagrant.d/insecure_private_key

and you can use this as your config file:
following is an example:

Host vg2
    HostName 10.0.0.2  ## using 1 is not a good idea.
    Port 22
    User vagrant
    IdentityFile ~/.vagrant.d/insecure_private_key
Host vg3
    HostName 10.0.0.3
    Port 22
    User vagrant
    IdentityFile ~/.vagrant.d/insecure_private_key

### and can directly use:
ssh vg2
ssh vg3
ssh vg4

Note: For 10.0.0.1, if you do ssh it don't work nicely...as this act as router ip address.

of go to the same directory from where you have the config file "Vagrantfile" and can do the following:

vagrant ssh web
vagrant ssh db
vagrant ssh vg4

### Where the file stay for very first time:

/home/amit/.vagrant.d/boxes/hashicorp-VAGRANTSLASH-precise32/0/virtualbox

amit@laptop:~/.vagrant.d/boxes/hashicorp-VAGRANTSLASH-precise32/0/virtualbox$ ls -l
total 288344
-rw------- 1 amit amit 295237632 Jun 28 18:07 box-disk1.vmdk
-rw------- 1 amit amit     14103 Jun 28 18:07 box.ovf
-rw-rw-r-- 1 amit amit        25 Jun 28 18:07 metadata.json
-rw-r--r-- 1 amit amit       505 Jun 28 18:07 Vagrantfile

No comments:

Post a Comment