Skip to content

Commit

Permalink
Fixing aws name issue and adding check for plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsmith committed Mar 30, 2018
1 parent d15f7d8 commit 5864310
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions lib/vagrant-hostsupdater/HostsUpdater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ def getIps
if ip = getAwsPublicIp
ips.push(ip)
else
@machine.config.vm.networks.each do |network|
key, options = network[0], network[1]
ip = options[:ip] if (key == :private_network || key == :public_network) && options[:hostsupdater] != "skip"
ips.push(ip) if ip
if options[:hostsupdater] == 'skip'
@ui.info '[vagrant-hostsupdater] Skipping adding host entries (config.vm.network hostsupdater: "skip" is set)'
@machine.config.vm.networks.each do |network|
key, options = network[0], network[1]
ip = options[:ip] if (key == :private_network || key == :public_network) && options[:hostsupdater] != "skip"
ips.push(ip) if ip
if options[:hostsupdater] == 'skip'
@ui.info '[vagrant-hostsupdater] Skipping adding host entries (config.vm.network hostsupdater: "skip" is set)'
end
end
end

Expand All @@ -42,7 +43,7 @@ def getIps
ips.push( '127.0.0.1' )
end
return ips
end
end

# Get a hash of hostnames indexed by ip, e.g. { 'ip1': ['host1'], 'ip2': ['host2', 'host3'] }
def getHostnames(ips)
Expand Down Expand Up @@ -182,7 +183,8 @@ def removeFromHosts(options = {})

def removeFromSshKnownHosts
if !@isWindowsHost
hostnames = getHostnames
ips = getIps
hostnames = getHostnames(ips)
hostnames.each do |hostname|
command = %Q(sed -i -e '/#{hostname}/ d' #@@ssh_known_hosts_path)
if system(command)
Expand Down Expand Up @@ -214,11 +216,11 @@ def adviseOnSudo
@ui.error "[vagrant-hostsupdater] Consider adding the following to your sudoers file:"
@ui.error "[vagrant-hostsupdater] https://github.com/cogitatio/vagrant-hostsupdater#suppressing-prompts-for-elevating-privileges"
end
private

def getAwsPublicIp
return nil if ! Vagrant.has_plugin?("vagrant-aws")
aws_conf = @machine.config.vm.get_provider_config(:aws)
return nil if ! aws_conf.is_a?(VagrantPlugins::AWS::Config)
return nil if ! aws_conf.is_a?(VagrantPlugins::Aws::Config)
filters = ( aws_conf.tags || [] ).map {|k,v| sprintf('"Name=tag:%s,Values=%s"', k, v) }.join(' ')
return nil if filters == ''
cmd = 'aws ec2 describe-instances --filter '+filters
Expand All @@ -232,7 +234,6 @@ def getAwsPublicIp
return nil
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/vagrant-hostsupdater/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module VagrantPlugins
module HostsUpdater
VERSION = '1.1.0'
VERSION = '1.1.1'
end
end

0 comments on commit 5864310

Please sign in to comment.