Created
September 28, 2012 10:28
-
-
Save ithinkihaveacat/3799060 to your computer and use it in GitHub Desktop.
Vagrantfile snippet to check that apache_server_name resolves to vm_ip
This file contains hidden or 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
| # 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