Created
October 22, 2015 20:48
-
-
Save zerodi/91412e37fc4671fae9cb to your computer and use it in GitHub Desktop.
Simple vagrant template with hostmanager plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
PROJECT_NAME="touchmy" | |
Vagrant.configure(2) do |config| | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.hostname = "#{PROJECT_NAME}.dev" | |
config.vm.network "private_network", type: "dhcp" | |
config.hostmanager.enabled = true | |
config.hostmanager.manage_host = true | |
config.hostmanager.aliases = %(#{PROJECT_NAME}) | |
config.hostmanager.ip_resolver = proc do |vm, resolving_vm| | |
begin | |
buffer = ''; | |
vm.communicate.execute("/sbin/ifconfig") do |type, data| | |
buffer += data if type == :stdout | |
end | |
ips = [] | |
ifconfigIPs = buffer.scan(/inet addr:(\d+\.\d+\.\d+\.\d+)/) | |
ifconfigIPs[0..ifconfigIPs.size].each do |ip| | |
ip = ip.first | |
next unless system "ping -c1 -t1 #{ip} > /dev/null" | |
ips.push(ip) unless ips.include? ip | |
end | |
ips.first | |
rescue StandardError => exc | |
return | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment