vagrant-goodhosts 1.0.1 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/vagrant-goodhosts/Action/UpdateHosts.rb +0 -1
- data/lib/vagrant-goodhosts/GoodHosts.rb +113 -100
- data/lib/vagrant-goodhosts/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 773499e5908599b791ece8dbfbeb82929508e5c9341af2603250e0d973ab1be2
|
4
|
+
data.tar.gz: 4b65f0a08a6779474a320e40ef0a0b924bb51c7c3334fa53a182da3dc856d5aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d71b200fa955218bdf800fc4da2d5c56d3b3d8719145b9961e8d9017d3215a34b21753dc4b10e151ca2616e05e24e0709a14d2058ba4b84da5ff1a9dbeb2d06e
|
7
|
+
data.tar.gz: d9ff6081767d318a1c91d96bf683c4791a809c60ec6e6d0fb39abc541d4e647dc50789717471493be2e8862ceda89718f33cb57e07804d4a3d1f6f71f5190cd2
|
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,67 @@
|
|
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
|
+
|
41
40
|
end
|
41
|
+
return ips
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
# https://stackoverflow.com/a/13586108/1902215
|
45
|
-
def
|
46
|
-
return os ||= (
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
)
|
45
|
+
def get_os_binary
|
46
|
+
return os ||= (host_os = RbConfig::CONFIG["host_os"]
|
47
|
+
case host_os
|
48
|
+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
49
|
+
:'cli.exe'
|
50
|
+
when /darwin|mac os/
|
51
|
+
:'cli_osx'
|
52
|
+
when /linux/
|
53
|
+
:'cli'
|
54
|
+
else
|
55
|
+
raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
|
56
|
+
end)
|
59
57
|
end
|
60
|
-
|
58
|
+
|
61
59
|
def get_cli
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
binary = get_os_binary
|
61
|
+
path = File.expand_path(File.dirname(File.dirname(__FILE__))) + "/vagrant-goodhosts/bundle/"
|
62
|
+
path = "#{path}#{binary}"
|
63
|
+
|
64
|
+
return path
|
67
65
|
end
|
68
66
|
|
69
67
|
# Get a hash of hostnames indexed by ip, e.g. { 'ip1': ['host1'], 'ip2': ['host2', 'host3'] }
|
@@ -83,80 +81,95 @@ module VagrantPlugins
|
|
83
81
|
end
|
84
82
|
end
|
85
83
|
|
86
|
-
# handle default hostname(s) if not already specified in the aliases
|
87
|
-
Array(@machine.config.vm.hostname).each do |host|
|
88
|
-
if hostnames.none? { |k, v| v.include?(host) }
|
89
|
-
ips.each do |ip|
|
90
|
-
hostnames[ip].unshift host
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
84
|
return hostnames
|
96
85
|
end
|
97
86
|
|
98
87
|
def addHostEntries
|
99
|
-
ips = getIps
|
100
|
-
hostnames = getHostnames(ips)
|
101
88
|
error = false
|
102
89
|
errorText = ""
|
103
90
|
cli = get_cli
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
91
|
+
hostnames_by_ips = generateHostnamesByIps
|
92
|
+
hostnames_by_ips.each do |ip_address, hostnames|
|
93
|
+
if ip_address.nil?
|
94
|
+
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
|
95
|
+
next
|
96
|
+
end
|
97
|
+
if cli.include? ".exe"
|
98
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "add", "--clean", ip_address, hostnames)
|
99
|
+
else
|
100
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "add", "--clean", ip_address, hostnames)
|
101
|
+
end
|
102
|
+
if !wait_thr.value.success?
|
103
|
+
error = true
|
104
|
+
errorText = stderr.read.strip
|
119
105
|
end
|
120
106
|
end
|
121
107
|
printReadme(error, errorText)
|
122
108
|
end
|
123
109
|
|
124
110
|
def removeHostEntries
|
125
|
-
ips = getIps
|
126
|
-
hostnames = getHostnames(ips)
|
127
111
|
error = false
|
128
112
|
errorText = ""
|
129
113
|
cli = get_cli
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
114
|
+
hostnames_by_ips = generateHostnamesByIps
|
115
|
+
hostnames_by_ips.each do |ip_address, hostnames|
|
116
|
+
if ip_address.nil?
|
117
|
+
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
|
118
|
+
next
|
119
|
+
end
|
120
|
+
if cli.include? ".exe"
|
121
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "remove", "--clean", ip_address, hostnames)
|
122
|
+
else
|
123
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "remove", "--clean", 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] - found 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] - found 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.7
|
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-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
|
-
rubygems_version: 3.1
|
84
|
+
rubygems_version: 3.2.0.rc.1
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: Enables Vagrant to update hosts file on the host machine with goodhosts
|