Skip to content

Instantly share code, notes, and snippets.

@scoates

scoates/Vagrantfile

Last active Oct 21, 2016
Embed
What would you like to do?
Ensure one VM ("gateway") is running before allowing the others
# Check to see that we have a gateway running before we allow the `up` of another VM
# This is a filthy hack
if ARGV[0] != 'up'
GATEWAY_STATUS = 'running' # this is irrelevant for everything but `vagrant up`
# if we don't do this, we could fork forever in the else block, here
else
GATEWAY_STATUS = `vagrant status --machine-readable | grep 'gateway,state,' | awk -F, {'print $4'}`.strip!
if GATEWAY_STATUS != 'running'
puts "*** The gateway is not running. You can not 'up' any other VMs."
end
end
Vagrant.configure(2) do |config|
if GATEWAY_STATUS == 'running'
config.vm.define :othervm, primary: false, autostart: false do |config|
bootstrap config.vm # custom
end
end
if GATEWAY_STATUS == 'running'
config.vm.define :yetanothervm, primary: false, autostart: false do |config|
bootstrap config.vm # custom
end
end
config.vm.define :gateway, primary: true, autostart: true do |config|
bootstrap config.vm # custom
end
end
@scoates

This comment has been minimized.

Copy link
Owner Author

@scoates scoates commented Oct 29, 2015

Someone tell me why this is a bad idea, and preferably: how to do it via internal APIs. (-:

@nicksloan

This comment has been minimized.

Copy link

@nicksloan nicksloan commented Oct 29, 2015

Does it matter if the gateway is up? What you really care about is connectivity over your VPN.Though I suppose the conditional is the really ugly part.

@scoates

This comment has been minimized.

Copy link
Owner Author

@scoates scoates commented Oct 21, 2016

Ha. Just noticed your comment @nicksloan. It does matter because we run apt-cacher-ng on the gateway, so other nodes "need" it to be running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment