[LRUG] Noob question re: vagrantfile

Jerry Steele ticktockhouse at gmail.com
Wed Jan 31 10:28:25 PST 2018


Hello list,

I've been lurking for quite a few years now, but I have a ruby language
question that most of you could probably solve in your sleep.

I'd like my vagrantfile to include a loop, into which I can pass variables
from a "hash of hashes"(?)

Here
<https://github.com/devopsgroup-io/vagrant-digitalocean/blob/master/README.md>
is the documentation for the vagrant plugin

Here is my code (the important parts anyway).

<<<<<<<<<<<<<<<<
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'
  }
 }

  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.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'
        provider.image = "#{machine_id['image']}"
      end
    end
  end
end
>>>>>>>>>>>>>>>>

I'm trying to loop through "cluster" and pull out the "name" and "image"
values, but with this code I just end up with

Vagrant:
* Unknown configuration section '[]'.

..which looks like it's hitting a syntax error somewhere.

Would anyone be able to point me in the right direction with this? It's
been driving me "loopy" for a while now :)

Thanks in advance
-- 
---

Jerry Steele
Telephone: +44 (0)7492 910225
http://www.ticktockhouse.co.uk
GPG: 43A3A8C6
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20180131/a54d6ad6/attachment.html>


More information about the Chat mailing list