Vaprobash icon indicating copy to clipboard operation
Vaprobash copied to clipboard

Define vars on multi VM Vagrant file

Open macklus opened this issue 10 years ago • 4 comments

Hi:

I use Vagrant to work with 3-4 VMs. I try Vaprobash and really like it, but i dont know how can i define vars (as mysql_root_password) inside a VM config block, and not in global block

is this possible?

Thanks in advance

macklus avatar Oct 31 '14 11:10 macklus

My Ruby is a bit limited, but I think using some Ruby objects for each server might be appropriate. That would mean editing the Vagrantfile to contain or include other objects, then using those for each VM.

Overall, however, I'd recommend using something more fancy. Consider using Ansible to setup each server. That would allow you to have one configuration usable for each VM in your "cluster". (Ansible can configure them all based on roles, or can make three duplicate servers - really any combo you might need).

fideloper avatar Oct 31 '14 12:10 fideloper

Hi I wish to keep it simple, so use ruby objects are better option than deploy throught Ansible or Puppet. Maybe can you put here an example of how works on Ruby objects to do that?

Really thanks.

macklus avatar Nov 03 '14 09:11 macklus

Can you show your Vagrantfile so I can see how you setup provisioning multiple servers?

fideloper avatar Nov 03 '14 13:11 fideloper

Simple sample of Vagrant file:

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

  # 
  config.vm.define "video" do |video|
    video.vm.box = "ubuntu/trusty64"
    video.vm.network "public_network", ip: "192.168.1.201", bridge: 'wlan0'
    video.vm.synced_folder "/home/macklus/desarrollo/videomensajes.net", "/home/vagrant/"

    video.vm.hostname = "videomensajes.local"

    video.vm.provider :virtualbox do |vb|
      vb.name = "videomensajes"
      vb.customize ["modifyvm", :id, "--memory", 2048]
    end

    # Provision
    video.vm.provision "shell", path: "scripts/base.sh", args: ["", "512", "UTC"]
    video.vm.provision "shell", path: "scripts/base_box_optimizations.sh", privileged: true
    video.vm.provision "shell", path: "scripts/php.sh", args: ["UTC", "false"]
    video.vm.provision "shell", path: "scripts/nginx.sh", args: ["192.168.1.221", "/home/vagrant/public_html", "videomensajes.local", ""]
    video.vm.provision "shell", path: "scripts/mariadb.sh", args: ["root", "true"]
    video.vm.provision "shell", path: "scripts/screen.sh"
    video.vm.provision "shell", path: "scripts/mailcatcher.sh"

  end
end

Is this enought ?

macklus avatar Nov 03 '14 15:11 macklus