Cannot attach VBox drive before Puppet Provisioning for Docker

21 views
Skip to first unread message

Francis Chan

unread,
Aug 10, 2015, 12:00:39 PM8/10/15
to Vagrant
I'm constructing 1..N nodes for a Mesos test bed but I need to mount a secondary drive for the Docker to each node because CentOS is by default using the loopback device.

When I loop each node I have attach the drive so I can run Puppet to configure it for Docker prior to starting the Docker service.  The problem is that the vm.provider section seems to always have to be at the end of the vm.define.  Anywhere else results in a "block (2 levels) in <top (required)>...", in this example, it says "registry" is undefined.

Vagrant = 1.74
VBox = 5.0.1r (using this cause I had to upgrade to Win10)

Ignore the size of the drive, right now just trying to figure this part out.

I'm just running "vagrant status" to let it parse the file.

This works:

    (1..3).each do |i|
        config.vm.define "registry#{i}" do |registry|
            registry.vm.provision "shell", inline: "echo hello"
            registry.vm.provider :virtualbox do |vb_config|
                second_disk = File.join(ENV["VAGRANT_HOME"], "/registrydisk#{i}2.vdi" ).gsub(%r{\\}) { "/" }
                puts second_disk
                unless File.exist?(second_disk)
                    vb_config.customize ['createhd', '--filename', second_disk, '--size', 100 * 1024]
                end
                    vb_config.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk]
                end
            end
        end
    end

This does not:

    (1..3).each do |i|
        config.vm.define "registry#{i}" do |registry|
            registry.vm.provision "shell", inline: "echo hello"
            registry.vm.provider :virtualbox do |vb_config|
                second_disk = File.join(ENV["VAGRANT_HOME"], "/registrydisk#{i}2.vdi" ).gsub(%r{\\}) { "/" }
                puts second_disk
                unless File.exist?(second_disk)
                    vb_config.customize ['createhd', '--filename', second_disk, '--size', 100 * 1024]
                end
                    vb_config.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk]
                end
            end
            registry.vm.provision "shell", inline: "echo hello again"
        end
    end

Alvaro Miranda Aguilera

unread,
Aug 10, 2015, 6:01:41 PM8/10/15
to vagra...@googlegroups.com
On Tue, Aug 11, 2015 at 4:00 AM, Francis Chan <poi...@gmail.com> wrote:
> (1..3).each do |i|
> config.vm.define "registry#{i}" do |registry|
> registry.vm.provision "shell", inline: "echo hello"
> registry.vm.provider :virtualbox do |vb_config|
> second_disk = File.join(ENV["VAGRANT_HOME"],
> "/registrydisk#{i}2.vdi" ).gsub(%r{\\}) { "/" }
> puts second_disk
> unless File.exist?(second_disk)
> vb_config.customize ['createhd', '--filename',
> second_disk, '--size', 100 * 1024]
> end
> vb_config.customize ['storageattach', :id,
> '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type',
> 'hdd', '--medium', second_disk]
> end
> end
> end
> end

Hello,

as |i| is defined outside of |registry| you can try to use a global
virtualbox value


Something like this:


(1..3).each do |i|

config.vm.provider :virtualbox do |vb_config|
second_disk = File.join(ENV["VAGRANT_HOME"],
"/registrydisk#{i}2.vdi" ).gsub(%r{\\}) { "/" }
puts second_disk
unless File.exist?(second_disk)
vb_config.customize ['createhd', '--filename', second_disk,
'--size', 100 * 1024]
end
vb_config.customize ['storageattach', :id, '--storagectl',
'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd',
'--medium', second_disk]
end


config.vm.define "registry#{i}" do |registry|
registry.vm.provision "shell", inline: "echo hello"
end
end
end
Reply all
Reply to author
Forward
0 new messages