vagrant-hostsupdater 1.0.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: aa5a906b2206c4c30ffc719ea0b078317cd884c8
4
- data.tar.gz: a8f1c3bd95b09e2d604a11a3c9281c904edeedc4
2
+ SHA256:
3
+ metadata.gz: 6c6b415c941a16c739c8f6b6c331fdd2b559c39e5c6ee3f7955779da3004e8b2
4
+ data.tar.gz: 8cc732de6682cca8f91f5a03c99eef3b9bf519dc758736b81f6616bcd2d941c8
5
5
  SHA512:
6
- metadata.gz: dbe7a6d519649649a9373b618176d13871fb442d2be630bb29fefe980bb5bbacabf3108d3a779bab82de53c460b61e1e77cae722940461913ad0ec072d17d4dd
7
- data.tar.gz: d004fb3ec7fde2201ae3b0eb67470cb4ae853c95b587b37536456ed788ccba65a6ce6aff686be481eff64e0287c96519878008cefe9193aba2ebf2bd20031d08
6
+ metadata.gz: 639e1a983ae8fd9011a02795f8dd7018ca9d16f06f7295d37f88e14c40a2061b346aff70111f2901181ca095d1767d420e092512aeb619203db99730376e1079
7
+ data.tar.gz: 7e0f3e55b11a5b2af496cccfcbf595558eb1ca9fdd7c891ff519684c3ea1b3121663c6603cde76ea9de359989e4a341a2e8066455a121f63e99561796f90db52
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ .idea
2
3
  *.rbc
3
4
  .bundle
4
5
  .config
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Falk Kühnel
1
+ Copyright 2018 Chris Smith
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -10,10 +10,10 @@
10
10
 
11
11
  This plugin adds an entry to your /etc/hosts file on the host system.
12
12
 
13
- On **up**, **resume** and **reload** commands, it tries to add the information, if its not already existant in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file.
13
+ On **up**, **resume** and **reload** commands, it tries to add the information, if it does not already exist in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file.
14
14
 
15
15
  On **halt**, **destroy**, and **suspend**, those entries will be removed again.
16
- By setting the `config.hostsupdater.remove_on_suspend = false`, **suspend** will not remove them.
16
+ By setting the `config.hostsupdater.remove_on_suspend = false`, **suspend** and **halt** will not remove them.
17
17
 
18
18
 
19
19
  ## Installation
@@ -38,6 +38,27 @@ You currently only need the `hostname` and a `:private_network` network with a f
38
38
 
39
39
  This IP address and the hostname will be used for the entry in the `/etc/hosts` file.
40
40
 
41
+ ### Multiple private network adapters
42
+
43
+ If you have multiple network adapters i.e.:
44
+
45
+ config.vm.network :private_network, ip: "10.0.0.1"
46
+ config.vm.network :private_network, ip: "10.0.0.2"
47
+
48
+ you can specify which hostnames are bound to which IP by passing a hash mapping the IP of the network to an array of hostnames to create, e.g.:
49
+
50
+ config.hostsupdater.aliases = {
51
+ '10.0.0.1' => ['foo.com', 'bar.com'],
52
+ '10.0.0.2' => ['baz.com', 'bat.com']
53
+ }
54
+
55
+ This will produce `/etc/hosts` entries like so:
56
+
57
+ 10.0.0.1 foo.com
58
+ 10.0.0.1 bar.com
59
+ 10.0.0.2 baz.com
60
+ 10.0.0.2 bat.com
61
+
41
62
  ### Skipping hostupdater
42
63
 
43
64
  To skip adding some entries to the /etc/hosts file add `hostsupdater: "skip"` option to network configuration:
@@ -52,17 +73,81 @@ Example:
52
73
  netmask: "255.255.240.0",
53
74
  hostsupdater: "skip"
54
75
 
76
+ ### Keeping Host Entries After Suspend/Halt
77
+
78
+ To keep your /etc/hosts file unchanged simply add the line below to your `VagrantFile`:
79
+
80
+ config.hostsupdater.remove_on_suspend = false
81
+
82
+ This disables vagrant-hostsupdater from running on **suspend** and **halt**.
83
+
84
+
85
+ ## Suppressing prompts for elevating privileges
86
+
87
+ These prompts exist to prevent anything that is being run by the user from inadvertently updating the hosts file.
88
+ If you understand the risks that go with supressing them, here's how to do it.
55
89
 
56
- ## Passwordless sudo
90
+ ### Linux/OS X: Passwordless sudo
57
91
 
58
- Add the following snippet to the sudoers file (for example, to `/etc/sudoers.d/vagrant_hostupdater`) to make it
59
- stop asking password when updating hosts file:
92
+ To allow vagrant to automatically update the hosts file without asking for a sudo password, add one of the following snippets to a new sudoers file include, i.e. `sudo visudo -f /etc/sudoers.d/vagrant_hostsupdater`.
93
+
94
+ For Ubuntu and most Linux environments:
60
95
 
61
96
  # Allow passwordless startup of Vagrant with vagrant-hostsupdater.
62
97
  Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts
63
- Cmnd_Alias VAGRANT_HOSTS_REMOVE = /usr/bin/sed -i -e /*/ d /etc/hosts
98
+ Cmnd_Alias VAGRANT_HOSTS_REMOVE = /bin/sed -i -e /*/ d /etc/hosts
64
99
  %sudo ALL=(root) NOPASSWD: VAGRANT_HOSTS_ADD, VAGRANT_HOSTS_REMOVE
65
-
100
+
101
+ For MacOS:
102
+
103
+ # Allow passwordless startup of Vagrant with vagrant-hostsupdater.
104
+ Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts
105
+ Cmnd_Alias VAGRANT_HOSTS_REMOVE = /usr/bin/sed -i -e /*/ d /etc/hosts
106
+ %admin ALL=(root) NOPASSWD: VAGRANT_HOSTS_ADD, VAGRANT_HOSTS_REMOVE
107
+
108
+ - If vagrant still asks for a password on commands that trigger the `VAGRANT_HOSTS_ADD` alias above (like **up**), you might need to wrap the echo statement in quotes, i.e. `Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c 'echo "*" >> /etc/hosts'`. This seems to be a problem with older versions of Linux and MacOS.
109
+ - If vagrant still asks for a password on commands that trigger the `VAGRANT_HOSTS_REMOVE` alias above (like
110
+ **halt** or **suspend**), this might indicate that the location of **sed** in the `VAGRANT_HOSTS_REMOVE` alias is
111
+ pointing to the wrong location. The solution is to find the location of **sed** (ex. `which sed`) and
112
+ replace that location in the `VAGRANT_HOSTS_REMOVE` alias.
113
+
114
+ ### Windows: UAC Prompt
115
+
116
+ You can use `cacls` or `icacls` to grant your user account permanent write permission to the system's hosts file.
117
+ You have to open an elevated command prompt; hold `❖ Win` and press `X`, then choose "Command Prompt (Admin)"
118
+
119
+ cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W
120
+
121
+ ## Using AWS as a Provider
122
+
123
+ If you'd like AWS as a provider using [vagrant-aws](https://github.com/mitchellh/vagrant-aws) or other plugin,
124
+ this plugin will detect the instance public IP by the tag infomations.
125
+ For example, [vagrant-aws](https://github.com/mitchellh/vagrant-aws) configures a tag infomations like the following.
126
+
127
+ config.vm.provider :aws do |aws, override|
128
+ aws.tags = {
129
+ "Name" => "vagrant",
130
+ ...
131
+ }
132
+ aws.elastic_ip = true
133
+ ...
134
+ end
135
+
136
+ * [AWS CLI](https://aws.amazon.com/cli/) is required
137
+ * The tag informations be unique for the instance
138
+ * Enable Elastic IP for the instance
139
+
140
+ ## Using Google as a provider
141
+
142
+ If you'd like a Google provider using [vagrant-google](https://github.com/mitchellh/vagrant-google), this plugin will detect the public IP from the name of the instance.
143
+ [vagrant-google](https://github.com/mitchellh/vagrant-google) provides a default name, but you can specify your own as follows:
144
+
145
+ config.vm.provider :google do |google, override|
146
+ google.name = "somename"
147
+ ...
148
+ end
149
+
150
+ * [Google Cloud SDK](https://cloud.google.com/sdk/) is required.
66
151
 
67
152
  ## Installing development version
68
153
 
@@ -87,6 +172,31 @@ vagrant plugin install vagrant-hostsupdater-*.gem
87
172
 
88
173
  ## Versions
89
174
 
175
+ ### 1.2.0
176
+ * Bugfix: Fixing null string [#188](/../../issues/188)
177
+
178
+ ### 1.1.1
179
+ * Bugfix: AWS Feature broke part of the code [#155](/../../issues/155)
180
+
181
+ ### 1.1.0
182
+ * Feature: Added AWS support [#74](/../../pull/74)
183
+ * Feature: Added libvirt provider [#122](/../../pull/122)
184
+ * Feature: Add support for multiple private network adapters [#96](/../../pull/96)
185
+ * Feature: Add support for VMs without private/public networking [#23](/../../issues/23)
186
+ * Feature: Add Docker support [#149](/../../pull/149)
187
+ * Bugfix: Windows users get UAC prompt [#40](/../../issues/40)
188
+ * Bugfix: Documentation update and type fix
189
+ * Misc: Added a note about suppressing UAC prompts
190
+
191
+ ### 1.0.2
192
+ * Feature: Added `remove_on_suspend` for `vagrant_halt` [#71](/../../issues/71)
193
+ * Feature: Skip entries if they already exist [#69](/../../issues/69)
194
+ * Bugfix: Fixing extra lines in /etc/hosts file [#87](/../../pull/87)
195
+ * Misc: Fix yellow text on UI [#39](/../../issues/39)
196
+
197
+ ### 1.0.1
198
+ * Bugfix: Fixing `up` issue on initialize [#28](/../../issues/28)
199
+
90
200
  ### 1.0.0
91
201
  * Stable release
92
202
  * Feature: Added `skip` flag [#69](/../../issues/69)
@@ -125,4 +235,4 @@ vagrant plugin install vagrant-hostsupdater-*.gem
125
235
  * fixed problem with removing hosts entries on destroy command (Thanks to Andy Bohne)
126
236
 
127
237
  ### 0.0.3
128
- * added aliases config option to define additional hostnames
238
+ * added aliases config option to define additional hostnames
@@ -14,10 +14,12 @@ module VagrantPlugins
14
14
  machine_action = env[:machine_action]
15
15
  if machine_action != :destroy || !@machine.id
16
16
  if machine_action != :suspend || false != @machine.config.hostsupdater.remove_on_suspend
17
- @ui.info "Removing hosts"
18
- removeHostEntries
19
- else
20
- @ui.info "Removing hosts on suspend disabled"
17
+ if machine_action != :halt || false != @machine.config.hostsupdater.remove_on_suspend
18
+ @ui.info "[vagrant-hostsupdater] Removing hosts"
19
+ removeHostEntries
20
+ else
21
+ @ui.info "[vagrant-hostsupdater] Removing hosts on suspend disabled"
22
+ end
21
23
  end
22
24
  end
23
25
  @app.call(env)
@@ -13,7 +13,7 @@ module VagrantPlugins
13
13
  end
14
14
 
15
15
  def call(env)
16
- @ui.info "Checking for host entries"
16
+ @ui.info "[vagrant-hostsupdater] Checking for host entries"
17
17
  addHostEntries()
18
18
  @app.call(env)
19
19
  end
@@ -1,43 +1,97 @@
1
+ require 'open3'
2
+
1
3
  module VagrantPlugins
2
4
  module HostsUpdater
3
5
  module HostsUpdater
4
- @@hosts_path = Vagrant::Util::Platform.windows? ? File.expand_path('system32/drivers/etc/hosts', ENV['windir']) : '/etc/hosts'
6
+ if ENV['VAGRANT_HOSTSUPDATER_PATH']
7
+ @@hosts_path = ENV['VAGRANT_HOSTSUPDATER_PATH']
8
+ else
9
+ @@hosts_path = Vagrant::Util::Platform.windows? ? File.expand_path('system32/drivers/etc/hosts', ENV['windir']) : '/etc/hosts'
10
+ end
11
+ @isWindowsHost = Vagrant::Util::Platform.windows?
12
+ @@ssh_known_hosts_path = '~/.ssh/known_hosts'
5
13
 
6
14
  def getIps
7
15
  ips = []
8
- @machine.config.vm.networks.each do |network|
9
- key, options = network[0], network[1]
10
- ip = options[:ip] if (key == :private_network || key == :public_network) && options[:hostsupdater] != "skip"
11
- ips.push(ip) if ip
12
- if options[:hostsupdater] == 'skip'
13
- @ui.info 'Skipping adding host entries (config.vm.network hostsupdater: "skip" is set)'
16
+
17
+ if ip = getAwsPublicIp
18
+ ips.push(ip)
19
+ elsif ip = getGooglePublicIp
20
+ ips.push(ip)
21
+ else
22
+ @machine.config.vm.networks.each do |network|
23
+ key, options = network[0], network[1]
24
+ ip = options[:ip] if (key == :private_network || key == :public_network) && options[:hostsupdater] != "skip"
25
+ ips.push(ip) if ip
26
+ if options[:hostsupdater] == 'skip'
27
+ @ui.info '[vagrant-hostsupdater] Skipping adding host entries (config.vm.network hostsupdater: "skip" is set)'
28
+ end
14
29
  end
15
30
  end
16
- return ips
17
- end
18
31
 
19
- def getHostnames
20
- hostnames = Array(@machine.config.vm.hostname)
21
- if @machine.config.hostsupdater.aliases
22
- hostnames.concat(@machine.config.hostsupdater.aliases)
32
+ if @machine.provider_name == :lxc
33
+ ip = @machine.provider.capability(:public_address)
34
+ ips.push(ip)
35
+ elsif @machine.provider_name == :docker
36
+ ip = @machine.provider.capability(:public_address)
37
+ ips.push(ip)
38
+ elsif @machine.provider_name == :libvirt
39
+ ssh_info = @machine.ssh_info
40
+ if ssh_info
41
+ ips.push(ssh_info[:host])
42
+ end
43
+ end
44
+ if not ips.any?
45
+ ips.push( '127.0.0.1' )
46
+ end
47
+ return ips.uniq
23
48
  end
49
+
50
+ # Get a hash of hostnames indexed by ip, e.g. { 'ip1': ['host1'], 'ip2': ['host2', 'host3'] }
51
+ def getHostnames(ips)
52
+ hostnames = Hash.new { |h, k| h[k] = [] }
53
+
54
+ case @machine.config.hostsupdater.aliases
55
+ when Array
56
+ # simple list of aliases to link to all ips
57
+ ips.each do |ip|
58
+ hostnames[ip] += @machine.config.hostsupdater.aliases
59
+ end
60
+ when Hash
61
+ # complex definition of aliases for various ips
62
+ @machine.config.hostsupdater.aliases.each do |ip, hosts|
63
+ hostnames[ip] += Array(hosts)
64
+ end
65
+ end
66
+
67
+ # handle default hostname(s) if not already specified in the aliases
68
+ Array(@machine.config.vm.hostname).each do |host|
69
+ if hostnames.none? { |k, v| v.include?(host) }
70
+ ips.each do |ip|
71
+ hostnames[ip].unshift host
72
+ end
73
+ end
74
+ end
75
+
24
76
  return hostnames
25
77
  end
26
78
 
27
- def addHostEntries()
79
+ def addHostEntries
28
80
  ips = getIps
29
- hostnames = getHostnames
81
+ hostnames = getHostnames(ips)
30
82
  file = File.open(@@hosts_path, "rb")
31
83
  hostsContents = file.read
32
84
  uuid = @machine.id
33
85
  name = @machine.name
34
86
  entries = []
35
87
  ips.each do |ip|
36
- hostEntries = getHostEntries(ip, hostnames, name, uuid)
37
- hostEntries.each do |hostEntry|
38
- escapedEntry = Regexp.quote(hostEntry)
39
- if !hostsContents.match(/#{escapedEntry}/)
40
- @ui.info "adding to (#@@hosts_path) : #{hostEntry}"
88
+ hostnames[ip].each do |hostname|
89
+ entryPattern = hostEntryPattern(ip, hostname)
90
+
91
+ if hostsContents.match(/#{entryPattern}/)
92
+ @ui.info "[vagrant-hostsupdater] found entry for: #{ip} #{hostname}"
93
+ else
94
+ hostEntry = createHostEntry(ip, hostname, name, uuid)
41
95
  entries.push(hostEntry)
42
96
  end
43
97
  end
@@ -51,7 +105,7 @@ module VagrantPlugins
51
105
 
52
106
  def removeHostEntries
53
107
  if !@machine.id and !@machine.config.hostsupdater.id
54
- @ui.warn "No machine id, nothing removed from #@@hosts_path"
108
+ @ui.info "[vagrant-hostsupdater] No machine id, nothing removed from #@@hosts_path"
55
109
  return
56
110
  end
57
111
  file = File.open(@@hosts_path, "rb")
@@ -59,7 +113,8 @@ module VagrantPlugins
59
113
  uuid = @machine.id || @machine.config.hostsupdater.id
60
114
  hashedId = Digest::MD5.hexdigest(uuid)
61
115
  if hostsContents.match(/#{hashedId}/)
62
- removeFromHosts
116
+ removeFromHosts
117
+ removeFromSshKnownHosts
63
118
  end
64
119
  end
65
120
 
@@ -67,21 +122,41 @@ module VagrantPlugins
67
122
  %Q(#{ip} #{hostnames.join(' ')} #{signature(name, uuid)})
68
123
  end
69
124
 
70
- def getHostEntries(ip, hostnames, name, uuid = self.uuid)
71
- entries = []
72
- hostnames.each do |hostname|
73
- entries.push(%Q(#{ip} #{hostname} #{signature(name, uuid)}))
74
- end
75
- return entries
125
+ def createHostEntry(ip, hostname, name, uuid = self.uuid)
126
+ %Q(#{ip} #{hostname} #{signature(name, uuid.to_s)})
127
+ end
128
+
129
+ # Create a regular expression that will match *any* entry describing the
130
+ # given IP/hostname pair. This is intentionally generic in order to
131
+ # recognize entries created by the end user.
132
+ def hostEntryPattern(ip, hostname)
133
+ Regexp.new('^\s*' + ip + '\s+' + hostname + '\s*(#.*)?$')
76
134
  end
77
135
 
78
136
  def addToHosts(entries)
79
137
  return if entries.length == 0
80
- content = entries.join("\n").strip.concat("\n")
138
+ content = entries.join("\n").strip
139
+
140
+ @ui.info "[vagrant-hostsupdater] Writing the following entries to (#@@hosts_path)"
141
+ @ui.info "[vagrant-hostsupdater] " + entries.join("\n[vagrant-hostsupdater] ")
81
142
  if !File.writable_real?(@@hosts_path)
82
- sudo(%Q(sh -c 'echo "#{content}" >> #@@hosts_path'))
143
+ @ui.info "[vagrant-hostsupdater] This operation requires administrative access. You may " +
144
+ "skip it by manually adding equivalent entries to the hosts file."
145
+ if !sudo(%Q(sh -c 'echo "#{content}" >> #@@hosts_path'))
146
+ @ui.error "[vagrant-hostsupdater] Failed to add hosts, could not use sudo"
147
+ adviseOnSudo
148
+ end
149
+ elsif Vagrant::Util::Platform.windows?
150
+ require 'tmpdir'
151
+ uuid = @machine.id || @machine.config.hostsupdater.id
152
+ tmpPath = File.join(Dir.tmpdir, 'hosts-' + uuid.to_s + '.cmd')
153
+ File.open(tmpPath, "w") do |tmpFile|
154
+ entries.each { |line| tmpFile.puts(">>\"#{@@hosts_path}\" echo #{line}") }
155
+ end
156
+ sudo(tmpPath)
157
+ File.delete(tmpPath)
83
158
  else
84
- content = "\n" + content
159
+ content = "\n" + content + "\n"
85
160
  hostsFile = File.open(@@hosts_path, "a")
86
161
  hostsFile.write(content)
87
162
  hostsFile.close()
@@ -91,20 +166,37 @@ module VagrantPlugins
91
166
  def removeFromHosts(options = {})
92
167
  uuid = @machine.id || @machine.config.hostsupdater.id
93
168
  hashedId = Digest::MD5.hexdigest(uuid)
94
- if !File.writable_real?(@@hosts_path)
95
- sudo(%Q(sed -i -e '/#{hashedId}/ d' #@@hosts_path))
169
+ if !File.writable_real?(@@hosts_path) || Vagrant::Util::Platform.windows?
170
+ if !sudo(%Q(sed -i -e '/#{hashedId}/ d' #@@hosts_path))
171
+ @ui.error "[vagrant-hostsupdater] Failed to remove hosts, could not use sudo"
172
+ adviseOnSudo
173
+ end
96
174
  else
97
175
  hosts = ""
98
176
  File.open(@@hosts_path).each do |line|
99
177
  hosts << line unless line.include?(hashedId)
100
178
  end
179
+ hosts.strip!
101
180
  hostsFile = File.open(@@hosts_path, "w")
102
181
  hostsFile.write(hosts)
103
182
  hostsFile.close()
104
183
  end
105
184
  end
106
185
 
107
-
186
+ def removeFromSshKnownHosts
187
+ if !@isWindowsHost
188
+ ips = getIps
189
+ hostnames = getHostnames(ips)
190
+ ips.each do |ip|
191
+ hostnames[ip].each do |hostname|
192
+ command = %Q(sed -i -e '/#{hostname}/ d' #@@ssh_known_hosts_path)
193
+ if system(command)
194
+ @ui.info "[vagrant-hostsupdater] Removed host: #{hostname} from ssh_known_hosts file: #@@ssh_known_hosts_path"
195
+ end
196
+ end
197
+ end
198
+ end
199
+ end
108
200
 
109
201
  def signature(name, uuid = self.uuid)
110
202
  hashedId = Digest::MD5.hexdigest(uuid)
@@ -114,11 +206,51 @@ module VagrantPlugins
114
206
  def sudo(command)
115
207
  return if !command
116
208
  if Vagrant::Util::Platform.windows?
117
- `#{command}`
209
+ require 'win32ole'
210
+ args = command.split(" ")
211
+ command = args.shift
212
+ sh = WIN32OLE.new('Shell.Application')
213
+ sh.ShellExecute(command, args.join(" "), '', 'runas', 0)
118
214
  else
119
- `sudo #{command}`
215
+ return system("sudo #{command}")
216
+ end
217
+ end
218
+
219
+ def adviseOnSudo
220
+ @ui.error "[vagrant-hostsupdater] Consider adding the following to your sudoers file:"
221
+ @ui.error "[vagrant-hostsupdater] https://github.com/cogitatio/vagrant-hostsupdater#suppressing-prompts-for-elevating-privileges"
222
+ end
223
+
224
+ def getAwsPublicIp
225
+ return nil if ! Vagrant.has_plugin?("vagrant-aws")
226
+ aws_conf = @machine.config.vm.get_provider_config(:aws)
227
+ return nil if ! aws_conf.is_a?(VagrantPlugins::AWS::Config)
228
+ filters = ( aws_conf.tags || [] ).map {|k,v| sprintf('"Name=tag:%s,Values=%s"', k, v) }.join(' ')
229
+ return nil if filters == ''
230
+ cmd = 'aws ec2 describe-instances --filter '+filters
231
+ stdout, stderr, stat = Open3.capture3(cmd)
232
+ @ui.error sprintf("Failed to execute '%s' : %s", cmd, stderr) if stderr != ''
233
+ return nil if stat.exitstatus != 0
234
+ begin
235
+ return JSON.parse(stdout)["Reservations"].first()["Instances"].first()["PublicIpAddress"]
236
+ rescue => e
237
+ @ui.error sprintf("Failed to get IP from the result of '%s' : %s", cmd, e.message)
238
+ return nil
120
239
  end
121
240
  end
241
+
242
+ def getGooglePublicIp
243
+ return nil if ! defined?(VagrantPlugins::Google)
244
+ google_conf = @machine.config.vm.get_provider_config(:google)
245
+ return nil if ! google_conf.is_a?(VagrantPlugins::Google::Config)
246
+ cmd = 'gcloud compute instances list --filter="name=%s" --format="value(networkInterfaces[0].accessConfigs[0].natIP)"'
247
+ cmd = sprintf(cmd, google_conf.name)
248
+ stdout, stderr, stat = Open3.capture3(cmd)
249
+ @ui.error "Failed to execute '#{cmd}' : #{stderr}" if stderr != ''
250
+ ip = stdout.strip
251
+ return nil if stat.exitstatus != 0 || ip == nil || ip == ''
252
+ return ip
253
+ end
122
254
  end
123
255
  end
124
256
  end
@@ -17,8 +17,7 @@ module VagrantPlugins
17
17
  end
18
18
 
19
19
  action_hook(:hostsupdater, :machine_action_up) do |hook|
20
- hook.prepend(Action::RemoveHosts)
21
- hook.after(Action::RemoveHosts, Action::UpdateHosts)
20
+ hook.append(Action::UpdateHosts)
22
21
  end
23
22
 
24
23
  action_hook(:hostsupdater, :machine_action_provision) do |hook|
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module HostsUpdater
3
- VERSION = "1.0.0"
3
+ VERSION = '1.2.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-hostsupdater
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Falk Kühnel
@@ -9,34 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-08 00:00:00.000000000 Z
12
+ date: 2020-12-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.3'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.3'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  description: Enables Vagrant to update hosts file on the host machine
@@ -47,7 +47,7 @@ executables: []
47
47
  extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
- - .gitignore
50
+ - ".gitignore"
51
51
  - Gemfile
52
52
  - LICENSE.txt
53
53
  - README.md
@@ -72,17 +72,16 @@ require_paths:
72
72
  - lib
73
73
  required_ruby_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  requirements: []
84
- rubyforge_project:
85
- rubygems_version: 2.0.14
84
+ rubygems_version: 3.1.2
86
85
  signing_key:
87
86
  specification_version: 4
88
87
  summary: Enables Vagrant to update hosts file on the host machine