vagrant-goodhosts 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/vagrant-goodhosts/GoodHosts.rb +103 -90
- data/lib/vagrant-goodhosts/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a413f4af6b28126f7bfa544c51fd1861d6809d3f2092ca512f4f3cb92b66a98
|
4
|
+
data.tar.gz: 278595e91fb77a7f0b1e9a439f21718c3c89c88d6cba2642cc15fc41f063c959
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e23da17547129d300c21c3c4850994ff34f936feb65cfb06d102cca35051ed679d22c535f4e7d0edb9019687b7816c9e755b64f4cef871c063aa00a7d2fa615a
|
7
|
+
data.tar.gz: db90290bfcfa853afc27f4993ab87cf0bafe81b2ad094888b1dafb83664cb3837847f6e814211b22676ede0f4ed3f24debfe3ba56490d8efdb4b7450c3ba9ac5
|
data/README.md
CHANGED
@@ -87,7 +87,7 @@ If you understand the risks that go with supressing them, here's how to do it.
|
|
87
87
|
### Linux/OS X: Passwordless sudo
|
88
88
|
|
89
89
|
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_goodhosts`.
|
90
|
-
|
90
|
+
The command path is printed when there are errors with sudo.
|
91
91
|
|
92
92
|
For Ubuntu and most Linux environments:
|
93
93
|
|
@@ -96,6 +96,8 @@ For Ubuntu and most Linux environments:
|
|
96
96
|
For MacOS:
|
97
97
|
|
98
98
|
%admin ALL=(root) NOPASSWD: [the-path]
|
99
|
+
|
100
|
+
Replace in both %sudo/%admin with the username it if it is not working for you.
|
99
101
|
|
100
102
|
### Windows: UAC Prompt
|
101
103
|
|
@@ -1,69 +1,66 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rbconfig"
|
2
|
+
require "open3"
|
3
3
|
|
4
4
|
module VagrantPlugins
|
5
5
|
module GoodHosts
|
6
6
|
module GoodHosts
|
7
|
-
|
8
7
|
def getIps
|
9
8
|
if Vagrant.has_plugin?("vagrant-hostsupdater")
|
10
|
-
|
9
|
+
@ui.warn "[vagrant-goodhosts] Warning: The vagrant-hostsupdater plugin is installed, hostsupdater always adds the VM name even if the VagrantFile says not to. This shouldn't cause issues, but if it does, uninstall hostsupdater"
|
11
10
|
end
|
12
|
-
|
11
|
+
|
13
12
|
ips = []
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
14
|
+
@machine.config.vm.networks.each do |network|
|
15
|
+
key, options = network[0], network[1]
|
16
|
+
ip = options[:ip] if (key == :private_network || key == :public_network) && options[:goodhosts] != "skip"
|
17
|
+
ips.push(ip) if ip
|
18
|
+
if options[:goodhosts] == "skip"
|
19
|
+
@ui.info '[vagrant-goodhosts] Skipping adding host entries (config.vm.network goodhosts: "skip" is set)'
|
20
|
+
end
|
21
|
+
|
22
|
+
@machine.config.vm.provider :hyperv do |v|
|
23
|
+
timeout = @machine.provider_config.ip_address_timeout
|
24
|
+
@ui.output("[vagrant-goodhosts] Waiting for the guest machine to report its IP address ( this might take some time, have patience )...")
|
25
|
+
@ui.detail("Timeout: #{timeout} seconds")
|
26
|
+
|
27
|
+
options = {
|
28
|
+
vmm_server_address: @machine.provider_config.vmm_server_address,
|
29
|
+
proxy_server_address: @machine.provider_config.proxy_server_address,
|
30
|
+
timeout: timeout,
|
31
|
+
machine: @machine,
|
32
|
+
}
|
33
|
+
network = @machine.provider.driver.read_guest_ip(options)
|
34
|
+
if network["ip"]
|
35
|
+
ips.push(network["ip"]) unless ips.include? network["ip"]
|
38
36
|
end
|
39
|
-
|
40
|
-
|
37
|
+
end
|
38
|
+
|
39
|
+
return ips
|
41
40
|
end
|
42
41
|
end
|
43
|
-
|
42
|
+
|
44
43
|
# https://stackoverflow.com/a/13586108/1902215
|
45
44
|
def get_OS
|
46
|
-
return os ||= (
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
)
|
45
|
+
return os ||= (host_os = RbConfig::CONFIG["host_os"]
|
46
|
+
case host_os
|
47
|
+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
48
|
+
:'cli.exe'
|
49
|
+
when /darwin|mac os/
|
50
|
+
:'cli_osx'
|
51
|
+
when /linux/
|
52
|
+
:'cli'
|
53
|
+
else
|
54
|
+
raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
|
55
|
+
end)
|
59
56
|
end
|
60
|
-
|
57
|
+
|
61
58
|
def get_cli
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
cli = get_OS
|
60
|
+
path = File.expand_path(File.dirname(File.dirname(__FILE__))) + "/vagrant-goodhosts/bundle/"
|
61
|
+
path = "#{path}#{cli}"
|
62
|
+
|
63
|
+
return path
|
67
64
|
end
|
68
65
|
|
69
66
|
# Get a hash of hostnames indexed by ip, e.g. { 'ip1': ['host1'], 'ip2': ['host2', 'host3'] }
|
@@ -96,67 +93,83 @@ module VagrantPlugins
|
|
96
93
|
end
|
97
94
|
|
98
95
|
def addHostEntries
|
99
|
-
ips = getIps
|
100
|
-
hostnames = getHostnames(ips)
|
101
96
|
error = false
|
102
97
|
errorText = ""
|
103
98
|
cli = get_cli
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
if !wait_thr.value.success?
|
115
|
-
error = true
|
116
|
-
errorText = stderr.read.strip
|
117
|
-
end
|
118
|
-
end
|
99
|
+
hostnames_by_ips = generateHostnamesByIps
|
100
|
+
hostnames_by_ips.each do |hostnames, ip_address|
|
101
|
+
if cli.include? ".exe"
|
102
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "a", ip_address, hostnames)
|
103
|
+
else
|
104
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "a", ip_address, hostnames)
|
105
|
+
end
|
106
|
+
if !wait_thr.value.success?
|
107
|
+
error = true
|
108
|
+
errorText = stderr.read.strip
|
119
109
|
end
|
120
110
|
end
|
121
111
|
printReadme(error, errorText)
|
122
112
|
end
|
123
113
|
|
124
114
|
def removeHostEntries
|
125
|
-
ips = getIps
|
126
|
-
hostnames = getHostnames(ips)
|
127
115
|
error = false
|
128
116
|
errorText = ""
|
129
117
|
cli = get_cli
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
if !wait_thr.value.success?
|
141
|
-
error = true
|
142
|
-
errorText = stderr.read.strip
|
143
|
-
end
|
144
|
-
end
|
118
|
+
hostnames_by_ips = generateHostnamesByIps
|
119
|
+
hostnames_by_ips.each do |hostnames, ip_address|
|
120
|
+
if cli.include? ".exe"
|
121
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "r", ip_address, hostnames)
|
122
|
+
else
|
123
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "r", ip_address, hostnames)
|
124
|
+
end
|
125
|
+
if !wait_thr.value.success?
|
126
|
+
error = true
|
127
|
+
errorText = stderr.read.strip
|
145
128
|
end
|
146
129
|
end
|
147
130
|
printReadme(error, errorText)
|
148
131
|
end
|
149
|
-
|
132
|
+
|
150
133
|
def printReadme(error, errorText)
|
151
134
|
if error
|
152
|
-
|
153
|
-
|
154
|
-
|
135
|
+
cli = get_cli
|
136
|
+
@ui.error "[vagrant-goodhosts] Issue executing goodhosts CLI: #{errorText}"
|
137
|
+
@ui.error "[vagrant-goodhosts] Cli path: #{cli}"
|
138
|
+
if cli.include? ".exe"
|
139
|
+
@ui.error "[vagrant-goodhosts] Check the readme at https://github.com/goodhosts/vagrant#windows-uac-prompt"
|
140
|
+
exit
|
141
|
+
else
|
155
142
|
@ui.error "[vagrant-goodhosts] Check the readme at https://github.com/goodhosts/vagrant#passwordless-sudo"
|
143
|
+
end
|
156
144
|
end
|
157
|
-
|
158
145
|
end
|
159
146
|
|
147
|
+
def generateHostnamesByIps()
|
148
|
+
hostnames_by_ips = []
|
149
|
+
ips = getIps
|
150
|
+
hostnames = getHostnames(ips)
|
151
|
+
if ips.count() > 1
|
152
|
+
ips.each do |ip|
|
153
|
+
ip_address = ip
|
154
|
+
hostnames[ip].each do |hostname|
|
155
|
+
if !ip_address.nil?
|
156
|
+
@ui.info "[vagrant-goodhosts] - remove entry for: #{ip_address} #{hostname}"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
hostnames_by_ips = { ip_address => hostnames[ip].join(" ") }
|
160
|
+
end
|
161
|
+
else
|
162
|
+
ip_address = ips[0]
|
163
|
+
hostnames[ip_address].each do |hostname|
|
164
|
+
if !ip_address.nil?
|
165
|
+
@ui.info "[vagrant-goodhosts] - remove entry for: #{ip_address} #{hostname}"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
|
169
|
+
end
|
170
|
+
|
171
|
+
return hostnames_by_ips
|
172
|
+
end
|
160
173
|
end
|
161
174
|
end
|
162
|
-
end
|
175
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-goodhosts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniele Scasciafratte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|