behavior vagrant file multiple machines with different memory settings.

76 views
Skip to first unread message

rajan.a...@codecentric.nl

unread,
Mar 11, 2016, 9:15:00 AM3/11/16
to Vagrant

Vagrant version

Installed Version: 1.8.1
Latest Version: 1.8.1

Host operating system

Ubuntu 15.10

Guest operating system

Ubuntu 14.04

Vagrantfile

Vagrant.configure(2) do |config|
  config.vm.synced_folder "files/ansible/", "/external/"

  config.vm.define "master" do |master|
   master.vm.box = "ubuntu/trusty64"
   master.vm.hostname = "master"
   master.vm.network "private_network", ip: "192.168.56.11"
   config.vm.provider "virtualbox" do |vbox1|
    vbox1.customize ["modifyvm", :id, "--memory", 4096]
    vbox1.customize ["modifyvm", :id, "--cpus", 4]
    vbox1.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
    config.vm.provision "ansible_local" do |ansible|
     ansible.verbose = true
     ansible.playbook = "/external/master-playbook.yml"
     end
    end
   end

  config.vm.define "slave" do |slave|
   slave.vm.box = "ubuntu/trusty64"
   slave.vm.hostname = "slave"
   slave.vm.network "private_network", ip: "192.168.56.12"
   config.vm.provider "virtualbox" do |vbox2|
    vbox2.customize ["modifyvm", :id, "--memory", 2048]
    vbox2.customize ["modifyvm", :id, "--cpus", 2]
    vbox2.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
    config.vm.provision "ansible_local" do |ansible|
     ansible.verbose = true
     ansible.playbook = "/external/slave-playbook.yml"
     end
    end
   end

end```

### Expected behavior
My intention was to create 2 different vbox machine with different memory and cpu settings. 

### Actual behavior
The vbox machines are created but both have the same memory settings (2048 MB), what am I doing wrong here? 

### References
Haven't found any yet

pixel fairy

unread,
Mar 11, 2016, 12:37:48 PM3/11/16
to Vagrant
config.vm refers to all of them. what you wanted was master.vm.provider... and slave.vm.provider.

Vagrant.configure(2) do |config|


  config
.vm.define "master" do |master|
   master
.vm.box = "ubuntu/trusty64"
   master
.vm.hostname = "master"
   master
.vm.network "private_network", ip: "192.168.56.11"

   master
.vm.provider "virtualbox" do |vbox1|

    vbox1
.customize ["modifyvm", :id, "--memory", 4096]
    vbox1
.customize ["modifyvm", :id, "--cpus", 4]

   
end
   
end

  config
.vm.define "slave" do |slave|
   slave
.vm.box = "ubuntu/trusty64"
   slave
.vm.hostname = "slave"
   slave
.vm.network "private_network", ip: "192.168.56.12"

   slave
.vm.provider "virtualbox" do |vbox2|

    vbox2
.customize ["modifyvm", :id, "--memory", 2048]
    vbox2
.customize ["modifyvm", :id, "--cpus", 2]

   
end
   
end

end

had to strip out the ansible parts to run it.


$ vagrant ssh master -- free
             total       used       free     shared    buffers     cached
Mem:       4048000     301300    3746700        604      12772     143640
-/+ buffers/cache:     144888    3903112
Swap:            0          0          0
$ vagrant ssh slave
-- free
             total       used       free     shared    buffers     cached
Mem:       2049896     283848    1766048        672      12740     143700
-/+ buffers/cache:     127408    1922488
Swap:            0          0          0

rajan.a...@codecentric.nl

unread,
Mar 11, 2016, 3:45:57 PM3/11/16
to Vagrant
Wow, thank you! It works like charm.
Reply all
Reply to author
Forward
0 new messages