From 6c1c684ca143c5d5d545dae01a49e2418a301508 Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Fri, 30 Mar 2018 16:38:34 -0700 Subject: [PATCH] Fixes the duplicate hosts entries and the error that sed throws when trying to remove known ssh hosts --- lib/vagrant-hostsupdater/HostsUpdater.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/vagrant-hostsupdater/HostsUpdater.rb b/lib/vagrant-hostsupdater/HostsUpdater.rb index 59a046f..f2f026e 100644 --- a/lib/vagrant-hostsupdater/HostsUpdater.rb +++ b/lib/vagrant-hostsupdater/HostsUpdater.rb @@ -42,7 +42,7 @@ def getIps if not ips.any? ips.push( '127.0.0.1' ) end - return ips + return ips.uniq end # Get a hash of hostnames indexed by ip, e.g. { 'ip1': ['host1'], 'ip2': ['host2', 'host3'] } @@ -185,10 +185,12 @@ def removeFromSshKnownHosts if !@isWindowsHost ips = getIps hostnames = getHostnames(ips) - hostnames.each do |hostname| - command = %Q(sed -i -e '/#{hostname}/ d' #@@ssh_known_hosts_path) - if system(command) - @ui.info "[vagrant-hostsupdater] Removed host: #{hostname} from ssh_known_hosts file: #@@ssh_known_hosts_path" + ips.each do |ip| + hostnames[ip].each do |hostname| + command = %Q(sed -i -e '/#{hostname}/ d' #@@ssh_known_hosts_path) + if system(command) + @ui.info "[vagrant-hostsupdater] Removed host: #{hostname} from ssh_known_hosts file: #@@ssh_known_hosts_path" + end end end end