Skip to content

Commit

Permalink
Merge pull request #157 from Jojo-Jojovich/fix-duplicate-hosts-sed-error
Browse files Browse the repository at this point in the history
Fixes the duplicate hosts entries and the error that sed throws when …
  • Loading branch information
cgsmith authored Mar 31, 2018
2 parents bbc9d02 + 6c1c684 commit 52dcfd1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/vagrant-hostsupdater/HostsUpdater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 52dcfd1

Please sign in to comment.