Skip to content

Instantly share code, notes, and snippets.

@zerodi
Created October 22, 2015 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerodi/91412e37fc4671fae9cb to your computer and use it in GitHub Desktop.
Save zerodi/91412e37fc4671fae9cb to your computer and use it in GitHub Desktop.
Simple vagrant template with hostmanager plugin
# -*- 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