- 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?
|
return @app.call(env) unless @machine.config.hostmanager.enabled?
|
||||||
@logger.info 'Updating /etc/hosts file automatically'
|
@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
|
# continue the action stack so the machine will be created
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
||||||
# update /etc/hosts file on each active machine
|
|
||||||
delete_guests(@machine,@machine.provider_name)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -100,6 +100,7 @@ module VagrantPlugins
|
||||||
def delete_entry(machine,file_name,sudo=false)
|
def delete_entry(machine,file_name,sudo=false)
|
||||||
host = machine.config.vm.hostname || name
|
host = machine.config.vm.hostname || name
|
||||||
temp_file_name = Dir::Tmpname.make_tmpname(File.join(machine.env.tmp_path,'hostmanager'), nil)
|
temp_file_name = Dir::Tmpname.make_tmpname(File.join(machine.env.tmp_path,'hostmanager'), nil)
|
||||||
|
if not machine.id.nil?
|
||||||
tempfile = File.open(temp_file_name,'w') do |f|
|
tempfile = File.open(temp_file_name,'w') do |f|
|
||||||
File.open(file_name,'r').each_line do |line|
|
File.open(file_name,'r').each_line do |line|
|
||||||
if line.match(/#{machine.id}$/).nil?
|
if line.match(/#{machine.id}$/).nil?
|
||||||
|
@ -116,6 +117,9 @@ module VagrantPlugins
|
||||||
machine.env.ui.info I18n.t('vagrant_hostmanager.action.run_sudo')
|
machine.env.ui.info I18n.t('vagrant_hostmanager.action.run_sudo')
|
||||||
@logger.info `sudo cp -v #{temp_file_name} #{file_name}`
|
@logger.info `sudo cp -v #{temp_file_name} #{file_name}`
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
@logger.warn "Machine id to delete was empty, skipping..."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_local(machine)
|
def update_local(machine)
|
||||||
|
|
|
@ -30,7 +30,7 @@ module VagrantPlugins
|
||||||
|
|
||||||
action_hook(:hostmanager, :machine_action_destroy) do |hook|
|
action_hook(:hostmanager, :machine_action_destroy) do |hook|
|
||||||
hook.prepend(Action::DeleteLocalEntry)
|
hook.prepend(Action::DeleteLocalEntry)
|
||||||
hook.append(Action::DeleteGuests)
|
hook.prepend(Action::DeleteGuests)
|
||||||
end
|
end
|
||||||
|
|
||||||
provisioner(:hostmanager) do
|
provisioner(:hostmanager) do
|
||||||
|
|
Loading…
Reference in New Issue