- Ensure that empty regex isn't processed for deletes.
- Set the hook for deletion to run prior to machine deletion so that the id is retrieveable.
This commit is contained in:
parent
733e451216
commit
782168492c
|
@ -20,11 +20,12 @@ module VagrantPlugins
|
|||
return @app.call(env) unless @machine.config.hostmanager.enabled?
|
||||
@logger.info 'Updating /etc/hosts file automatically'
|
||||
|
||||
# update /etc/hosts file on each active machine
|
||||
delete_guests(@machine,@machine.provider_name)
|
||||
|
||||
# continue the action stack so the machine will be created
|
||||
@app.call(env)
|
||||
|
||||
# update /etc/hosts file on each active machine
|
||||
delete_guests(@machine,@machine.provider_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -100,21 +100,25 @@ module VagrantPlugins
|
|||
def delete_entry(machine,file_name,sudo=false)
|
||||
host = machine.config.vm.hostname || name
|
||||
temp_file_name = Dir::Tmpname.make_tmpname(File.join(machine.env.tmp_path,'hostmanager'), nil)
|
||||
tempfile = File.open(temp_file_name,'w') do |f|
|
||||
File.open(file_name,'r').each_line do |line|
|
||||
if line.match(/#{machine.id}$/).nil?
|
||||
f << line
|
||||
else
|
||||
@logger.info "Matched #{machine.id}"
|
||||
if not machine.id.nil?
|
||||
tempfile = File.open(temp_file_name,'w') do |f|
|
||||
File.open(file_name,'r').each_line do |line|
|
||||
if line.match(/#{machine.id}$/).nil?
|
||||
f << line
|
||||
else
|
||||
@logger.info "Matched #{machine.id}"
|
||||
end
|
||||
end
|
||||
end
|
||||
if sudo == false
|
||||
@logger.info "copy #{temp_file_name} #{file_name}"
|
||||
FileUtils.cp(temp_file_name,file_name)
|
||||
else
|
||||
machine.env.ui.info I18n.t('vagrant_hostmanager.action.run_sudo')
|
||||
@logger.info `sudo cp -v #{temp_file_name} #{file_name}`
|
||||
end
|
||||
end
|
||||
end
|
||||
if sudo == false
|
||||
@logger.info "copy #{temp_file_name} #{file_name}"
|
||||
FileUtils.cp(temp_file_name,file_name)
|
||||
else
|
||||
machine.env.ui.info I18n.t('vagrant_hostmanager.action.run_sudo')
|
||||
@logger.info `sudo cp -v #{temp_file_name} #{file_name}`
|
||||
@logger.warn "Machine id to delete was empty, skipping..."
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ module VagrantPlugins
|
|||
|
||||
action_hook(:hostmanager, :machine_action_destroy) do |hook|
|
||||
hook.prepend(Action::DeleteLocalEntry)
|
||||
hook.append(Action::DeleteGuests)
|
||||
hook.prepend(Action::DeleteGuests)
|
||||
end
|
||||
|
||||
provisioner(:hostmanager) do
|
||||
|
|
Loading…
Reference in New Issue