Skip to content

Instantly share code, notes, and snippets.

@ithinkihaveacat
Created September 28, 2012 10:28
Show Gist options
  • Select an option

  • Save ithinkihaveacat/3799060 to your computer and use it in GitHub Desktop.

Select an option

Save ithinkihaveacat/3799060 to your computer and use it in GitHub Desktop.
Vagrantfile snippet to check that apache_server_name resolves to vm_ip
# Vagrantfile snippet to check that apache_server_name resolves to vm_ip (i.e.
# assuming that the rest of the Vagrantfile configures a VM in this way).
apache_server_name = "myproject.local"
vm_ip = "192.168.33.111"
begin
res = Socket::getaddrinfo(apache_server_name, nil, Socket::AF_INET)
rescue SocketError => e
# s doesn't resolve to anything at all
print "error: [#{apache_server_name}] does not resolve to [#{vm_ip}] (edit /etc/hosts)\n"
exit
end
if !(Socket::getaddrinfo(apache_server_name, nil, Socket::AF_INET).map { |ip| ip[3] }).any? { |ip| ip == vm_ip } then
# s resolves to "wrong" IP
print "error: [#{apache_server_name}] does not resolve to [#{vm_ip}] (edit /etc/hosts)\n"
exit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment