Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the hostmanager.extra_hosts attribute, attempt to fix issue #223 #248

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allow simplified array definition in the hostmanager.extra_hosts attr…
…ibute
  • Loading branch information
javier-lopez committed Jan 23, 2018
commit c9bd9d32286519b80155e63e6c93bae738b8cd61
19 changes: 16 additions & 3 deletions lib/vagrant-hostmanager/hosts_file/updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,26 @@ def update_content(file_content, resolving_machine, include_id, line_endings)
.join
unless body.empty? #only when there is at least one active machine
extra_hosts = @config.hostmanager.extra_hosts
body << extra_hosts
.map { |ip, aliases| aliases.map{|a| "#{ip}\t#{a}"}.join("\n") + "\n\n" }
.join
case depth(extra_hosts)
#allow single defs: config.hostmanager.extra_hosts = ['172.28.128.100', ['db.dev']]
when 1
body << extra_hosts
.map { |ip, aliases| "#{ip}\t#{aliases}"}.join(" ") + "\n\n"
#and multiple ones, config.hostmanager.extra_hosts = [['172.28.128.100', ['db.dev']], ['0.0.0.0', ['db.io', 'db.dev']] ]
when 2
body << extra_hosts
.map { |ip, aliases| aliases.map{|a| "#{ip}\t#{a}"}.join("\n") + "\n\n" }
.join
end
end
get_new_content(header, footer, body, file_content, line_endings)
end

def depth(array)
return 0 unless array.is_a?(Array)
return 1 + depth(array[0])
end

def get_hosts_file_entry(machine, resolving_machine)
ip = get_ip_address(machine, resolving_machine)
host = machine.config.vm.hostname || machine.name
Expand Down