Skip to content

Instantly share code, notes, and snippets.

@vasiliishvakin
Created May 21, 2014 13:26
Show Gist options
  • Save vasiliishvakin/52d37dd08149e114ab1a to your computer and use it in GitHub Desktop.
Save vasiliishvakin/52d37dd08149e114ab1a to your computer and use it in GitHub Desktop.
# Local Machine Hosts
#
# If the Vagrant plugin hostsupdater (https://github.com/cogitatio/vagrant-hostsupdater) is
# installed, the following will automatically configure your local machine's hosts file to
# be aware of the domains specified below. Watch the provisioning script as you may be
# required to enter a password for Vagrant to access your hosts file.
#
# By default, we'll include the domains setup by dv through the dv-hosts file
# located in the www/ directory.
#
# Other domains can be automatically added by including a dv-hosts file containing
# individual domains separated by whitespace in subdirectories of www/.
if defined? VagrantPlugins::HostsUpdater
# Capture the paths to all dv-hosts files under the www/ directory.
paths = []
Dir.glob(vagrant_dir + '/www/**/dv-hosts').each do |path|
paths << path
end
# Parse through the dv-hosts files in each of the found paths and put the hosts
# that are found into a single array.
hosts = []
paths.each do |path|
new_hosts = []
file_hosts = IO.read(path).split( "\n" )
file_hosts.each do |line|
if line[0..0] != "#"
new_hosts << line
end
end
hosts.concat new_hosts
end
# Pass the final hosts array to the hostsupdate plugin so it can perform magic.
config.hostsupdater.aliases = hosts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment