vagrant-goodhosts 1.0.0 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -3
- 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: 77a1b25e87a6f494d365411f2094bf55b3bb44d52a760aea2cccf81147f326f2
|
4
|
+
data.tar.gz: a8212f3941c4fd3e55ddc6ce50c1d0a92fb892bf94f2be58f71b89d817c1f972
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2d1047db323f73cf93dd19c96f19df9ca4f0226151dab857f0a4e73d87a828cd1edc984cf76adc2ab4115ffc9844801679fe0517b674db88052354421a286e6
|
7
|
+
data.tar.gz: 17ff9509b9b35ea2adfc423754f549c9edffc15809e3cdc74e24f780bb9976d43d4428a2a1dff9dbc3f6a59ad333e8b84ab9cec2057493dfa6796fd198f6ccc7
|
data/README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# Vagrant::Goodhosts
|
2
2
|
|
3
|
-
This vagrant plugin adds host file entries to the host pointing to the guest VM, using the [GoodHosts](https://github.com/goodhosts/cli) cli tool. This plugin is based on [vagrant-hostsupdater](https://github.com/cogitatio/vagrant-hostsupdater) and aims to be compatible with the same config parameters.
|
3
|
+
This vagrant plugin adds host file entries to the host pointing to the guest VM, using the [GoodHosts](https://github.com/goodhosts/cli) cli tool. This plugin is based on [vagrant-hostsupdater](https://github.com/cogitatio/vagrant-hostsupdater) and aims to be compatible with the same config parameters.
|
4
4
|
|
5
5
|
On **up**, **resume** and **reload** commands, it tries to add the hosts if they do not already exist in your hosts file. If it needs to be added, you will be asked for the `sudo` password to make the necessary edits.
|
6
6
|
|
7
7
|
On **halt**, **destroy**, and **suspend**, those entries will be removed again. By setting the `config.goodhosts.remove_on_suspend = false`, **suspend** and **halt** will not remove them.
|
8
8
|
|
9
|
-
|
10
9
|
## Installation
|
11
10
|
|
12
11
|
```shell
|
@@ -37,6 +36,11 @@ config.goodhosts.aliases = ["alias.testing.de", "alias2.somedomain.com"]
|
|
37
36
|
|
38
37
|
This IP address and the hostname will be used for the entry in the `/etc/hosts` file.
|
39
38
|
|
39
|
+
### vagrant-hostsupdater conflicts
|
40
|
+
|
41
|
+
The original plugin has the issue of be executed in any vagrant environment, also that is not using and will add a rule in the hosts file that is not generated by this one.
|
42
|
+
To avoid issues is better to remove that plugin and in case update accordingly the Vagrantfile if use it. Require just a change of the reference of the plugin name as the example above.
|
43
|
+
|
40
44
|
### Multiple private network adapters
|
41
45
|
|
42
46
|
If you have multiple network adapters i.e.:
|
@@ -83,7 +87,7 @@ If you understand the risks that go with supressing them, here's how to do it.
|
|
83
87
|
### Linux/OS X: Passwordless sudo
|
84
88
|
|
85
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`.
|
86
|
-
|
90
|
+
The command path is printed when there are errors with sudo.
|
87
91
|
|
88
92
|
For Ubuntu and most Linux environments:
|
89
93
|
|
@@ -92,6 +96,8 @@ For Ubuntu and most Linux environments:
|
|
92
96
|
For MacOS:
|
93
97
|
|
94
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.
|
95
101
|
|
96
102
|
### Windows: UAC Prompt
|
97
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", "cl", ip_address, hostnames)
|
99
|
+
else
|
100
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "add", "cl", 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", "cl", ip_address, hostnames)
|
122
|
+
else
|
123
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "remove", "cl", 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.6
|
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.1.4
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: Enables Vagrant to update hosts file on the host machine with goodhosts
|