Multi-machine Vagrantfile driving me loopy (!)

25 views
Skip to first unread message

Jerry Steele

unread,
Jan 30, 2018, 7:01:50 PM1/30/18
to Vagrant
I'm trying to bring up some DO boxes in vagrant

# vim: ft=ruby

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

  cluster
= {
   
0 => {
     
'name' => 'backups',
     
'image' => 'ubuntu-16-04-x64'
   
},
   
1 => {
     
'name' => 'client1',
     
'image' =>  'debian-9-x64'
   
},
   
2 => {
     
'name' => 'client2',
     
'image' =>  'debian-8-x64'
   
},
   
3 => {
     
'name' => 'client3',
     
'image' =>  'ubuntu-16-04-x64'
 
}
 
}

  config
.vm.provision "ansible" do |ansible|
    ansible
.playbook = "playbook/site.yml"
    ansible
.host_vars = {

   
}
 
end

  cluster
.each do |i, machine|
    config
.vm.define "#{machine['name']}" do |machine_id|
      machine_id
.ssh.private_key_path = '~/.ssh/id_rsa.digitalocean'
      machine_id
.vm.box = 'digital_ocean'
      machine_id
.vm.hostname = "#{machine_id['name']}"
      machine_id
.image = "#{machine_id['image']}"

      machine_id
.vm.provider :digital_ocean do |provider, override|
       
override.vm.box_url = "https://github.com/devopsgroup-io/vagrant-digitalocean/raw/master/box/digital_ocean.box"
        provider
.token = `echo $DO_API_TOKEN`
        provider
.region = 'lon1'
        provider
.size = 's-1vcpu-1gb'
     
end
   
end
 
end
end


As you can see, the variables will be the hostname and the image used for each box. I found something like the obvoe online and have tried to adapt it, but I've had massive problems. I'm still a bit new to Ruby, and am having some problems with the syntax. At this point, I get errors like:


vm:
* The hostname set for the VM should only contain letters, numbers,
hyphens
or dots. It cannot start with a hyphen or dot.

Vagrant:
* Unknown configuration section '[]'.
* Unknown configuration section 'image='.


Obviously the interpolation is not working. Any idea where to start with this? I think I just need a bit of extra knowledge to work out where I'm going wrong with both Vagrant and loops in Ruby.

Thanks

Jerry
Reply all
Reply to author
Forward
0 new messages