vagrant-goodhosts 1.0.0.pre.beta4 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +55 -34
- data/lib/vagrant-goodhosts/GoodHosts.rb +114 -92
- data/lib/vagrant-goodhosts/plugin.rb +0 -5
- data/lib/vagrant-goodhosts/version.rb +1 -1
- data/vagrant-goodhosts.gemspec +1 -1
- metadata +5 -6
- data/lib/vagrant-goodhosts/command.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d08aeb238e55a6b9c10399ed2bb6cdf227e223bbde08e4a6dfb11366e67e5ee
|
4
|
+
data.tar.gz: 59169325206bd3f62a0b040d259fe14dc42dd3fa310822e5bccd4fc04beb15c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4be9ec9e1d21b768de7c7a711f49daebec9606d28bdaf0a897f6deacb45faa76c1c6aec786a1701f119b5e6f4a4152a39315b58bfef77e9fd6dfa14744656519
|
7
|
+
data.tar.gz: 2a3e60b74d59745cea020b37dbd946ab0a1a14cbd77041727b20c0f55d9879871704512540578cbe8a247a86d55608c72692b016b061438569d231d4606e14b8
|
data/README.md
CHANGED
@@ -1,63 +1,82 @@
|
|
1
1
|
# Vagrant::Goodhosts
|
2
2
|
|
3
|
-
This plugin adds
|
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
|
-
On **up**, **resume** and **reload** commands, it tries to add the
|
6
|
-
|
7
|
-
On **halt**, **destroy**, and **suspend**, those entries will be removed again.
|
8
|
-
By setting the `config.goodhosts.remove_on_suspend = false`, **suspend** and **halt** will not remove them.
|
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.
|
9
6
|
|
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.
|
10
8
|
|
11
9
|
## Installation
|
12
10
|
|
13
|
-
|
11
|
+
```shell
|
12
|
+
vagrant plugin install vagrant-goodhosts
|
13
|
+
```
|
14
14
|
|
15
|
-
|
15
|
+
To uninstall :
|
16
16
|
|
17
|
-
|
17
|
+
```shell
|
18
|
+
vagrant plugin uninstall vagrant-goodhosts
|
19
|
+
```
|
18
20
|
|
19
|
-
|
21
|
+
To update the plugin:
|
20
22
|
|
21
|
-
|
23
|
+
```shell
|
24
|
+
vagrant plugin update vagrant-goodhosts
|
25
|
+
```
|
22
26
|
|
23
27
|
## Usage
|
24
28
|
|
25
29
|
You currently only need the `hostname` and a `:private_network` network with a fixed IP address.
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
```ruby
|
32
|
+
config.vm.network :private_network, ip: "192.168.3.10"
|
33
|
+
config.vm.hostname = "www.testing.de"
|
34
|
+
config.goodhosts.aliases = ["alias.testing.de", "alias2.somedomain.com"]
|
35
|
+
```
|
30
36
|
|
31
37
|
This IP address and the hostname will be used for the entry in the `/etc/hosts` file.
|
32
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
|
+
|
33
44
|
### Multiple private network adapters
|
34
45
|
|
35
46
|
If you have multiple network adapters i.e.:
|
36
47
|
|
37
|
-
|
38
|
-
|
48
|
+
```ruby
|
49
|
+
config.vm.network :private_network, ip: "10.0.0.1"
|
50
|
+
config.vm.network :private_network, ip: "10.0.0.2"
|
51
|
+
```
|
39
52
|
|
40
|
-
|
53
|
+
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.:
|
41
54
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
55
|
+
```ruby
|
56
|
+
config.goodhosts.aliases = {
|
57
|
+
'10.0.0.1' => ['foo.com', 'bar.com'],
|
58
|
+
'10.0.0.2' => ['baz.com', 'bat.com']
|
59
|
+
}
|
60
|
+
```
|
46
61
|
|
47
62
|
This will produce `/etc/hosts` entries like so:
|
48
63
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
64
|
+
```
|
65
|
+
10.0.0.1 foo.com
|
66
|
+
10.0.0.1 bar.com
|
67
|
+
10.0.0.2 baz.com
|
68
|
+
10.0.0.2 bat.com
|
69
|
+
```
|
70
|
+
|
54
71
|
### Keeping Host Entries After Suspend/Halt
|
55
72
|
|
56
|
-
To keep your
|
73
|
+
To keep your `/etc/hosts` file unchanged simply add the line below to your `VagrantFile`:
|
57
74
|
|
58
|
-
|
59
|
-
|
60
|
-
|
75
|
+
```ruby
|
76
|
+
config.goodhosts.remove_on_suspend = false
|
77
|
+
```
|
78
|
+
|
79
|
+
This disables `vagrant-goodhosts` from running on **suspend** and **halt**.
|
61
80
|
|
62
81
|
|
63
82
|
## Suppressing prompts for elevating privileges
|
@@ -68,7 +87,7 @@ If you understand the risks that go with supressing them, here's how to do it.
|
|
68
87
|
### Linux/OS X: Passwordless sudo
|
69
88
|
|
70
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`.
|
71
|
-
|
90
|
+
The command path is printed when there are errors with sudo.
|
72
91
|
|
73
92
|
For Ubuntu and most Linux environments:
|
74
93
|
|
@@ -77,6 +96,8 @@ For Ubuntu and most Linux environments:
|
|
77
96
|
For MacOS:
|
78
97
|
|
79
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.
|
80
101
|
|
81
102
|
### Windows: UAC Prompt
|
82
103
|
|
@@ -85,12 +106,12 @@ You have to open an elevated command prompt; hold `❖ Win` and press `X`, then
|
|
85
106
|
|
86
107
|
cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W
|
87
108
|
|
88
|
-
## Installing
|
109
|
+
## Installing The Development Version
|
89
110
|
|
90
|
-
If you would like to install vagrant-goodhosts
|
111
|
+
If you would like to install `vagrant-goodhosts` to make contributions or changes, run the following commands::
|
91
112
|
|
92
|
-
```
|
93
|
-
git clone https://github.com/goodhosts/vagrant
|
113
|
+
```shell
|
114
|
+
git clone https://github.com/goodhosts/vagrant vagrant-goodhosts
|
94
115
|
cd vagrant-goodhosts
|
95
116
|
git checkout develop
|
96
117
|
./package.sh
|
@@ -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'] }
|
@@ -96,67 +94,91 @@ module VagrantPlugins
|
|
96
94
|
end
|
97
95
|
|
98
96
|
def addHostEntries
|
99
|
-
ips = getIps
|
100
|
-
hostnames = getHostnames(ips)
|
101
97
|
error = false
|
102
98
|
errorText = ""
|
103
99
|
cli = get_cli
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
100
|
+
hostnames_by_ips = generateHostnamesByIps
|
101
|
+
hostnames_by_ips.each do |ip_address, hostnames|
|
102
|
+
if ip_address.nil?
|
103
|
+
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
|
104
|
+
next
|
105
|
+
end
|
106
|
+
if cli.include? ".exe"
|
107
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "add", ip_address, hostnames)
|
108
|
+
else
|
109
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "add", ip_address, hostnames)
|
110
|
+
end
|
111
|
+
if !wait_thr.value.success?
|
112
|
+
error = true
|
113
|
+
errorText = stderr.read.strip
|
119
114
|
end
|
120
115
|
end
|
121
116
|
printReadme(error, errorText)
|
122
117
|
end
|
123
118
|
|
124
119
|
def removeHostEntries
|
125
|
-
ips = getIps
|
126
|
-
hostnames = getHostnames(ips)
|
127
120
|
error = false
|
128
121
|
errorText = ""
|
129
122
|
cli = get_cli
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
123
|
+
hostnames_by_ips = generateHostnamesByIps
|
124
|
+
hostnames_by_ips.each do |ip_address, hostnames|
|
125
|
+
if ip_address.nil?
|
126
|
+
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
|
127
|
+
next
|
128
|
+
end
|
129
|
+
if cli.include? ".exe"
|
130
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "remove", ip_address, hostnames)
|
131
|
+
else
|
132
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "remove", ip_address, hostnames)
|
133
|
+
end
|
134
|
+
if !wait_thr.value.success?
|
135
|
+
error = true
|
136
|
+
errorText = stderr.read.strip
|
145
137
|
end
|
146
138
|
end
|
147
139
|
printReadme(error, errorText)
|
148
140
|
end
|
149
|
-
|
141
|
+
|
150
142
|
def printReadme(error, errorText)
|
151
143
|
if error
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
144
|
+
cli = get_cli
|
145
|
+
@ui.error "[vagrant-goodhosts] Issue executing goodhosts CLI: #{errorText}"
|
146
|
+
@ui.error "[vagrant-goodhosts] Cli path: #{cli}"
|
147
|
+
if cli.include? ".exe"
|
148
|
+
@ui.error "[vagrant-goodhosts] Check the readme at https://github.com/goodhosts/vagrant#windows-uac-prompt"
|
149
|
+
exit
|
150
|
+
else
|
151
|
+
@ui.error "[vagrant-goodhosts] Check the readme at https://github.com/goodhosts/vagrant#passwordless-sudo"
|
152
|
+
end
|
156
153
|
end
|
157
|
-
|
158
154
|
end
|
159
155
|
|
156
|
+
def generateHostnamesByIps()
|
157
|
+
hostnames_by_ips = []
|
158
|
+
ips = getIps
|
159
|
+
hostnames = getHostnames(ips)
|
160
|
+
if ips.count() > 1
|
161
|
+
ips.each do |ip|
|
162
|
+
ip_address = ip
|
163
|
+
hostnames[ip].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].join(" ") }
|
169
|
+
end
|
170
|
+
else
|
171
|
+
ip_address = ips[0]
|
172
|
+
hostnames[ip_address].each do |hostname|
|
173
|
+
if !ip_address.nil?
|
174
|
+
@ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
|
178
|
+
end
|
179
|
+
|
180
|
+
return hostnames_by_ips
|
181
|
+
end
|
160
182
|
end
|
161
183
|
end
|
162
|
-
end
|
184
|
+
end
|
data/vagrant-goodhosts.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['mte90net@gmail.com']
|
11
11
|
spec.description = %q{Enables Vagrant to update hosts file on the host machine with goodhosts}
|
12
12
|
spec.summary = spec.description
|
13
|
-
spec.homepage = 'https://github.com/
|
13
|
+
spec.homepage = 'https://github.com/goodhosts/vagrant'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
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.4
|
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-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -57,13 +57,12 @@ files:
|
|
57
57
|
- lib/vagrant-goodhosts/bundle/cli
|
58
58
|
- lib/vagrant-goodhosts/bundle/cli.exe
|
59
59
|
- lib/vagrant-goodhosts/bundle/cli_osx
|
60
|
-
- lib/vagrant-goodhosts/command.rb
|
61
60
|
- lib/vagrant-goodhosts/config.rb
|
62
61
|
- lib/vagrant-goodhosts/plugin.rb
|
63
62
|
- lib/vagrant-goodhosts/version.rb
|
64
63
|
- package.sh
|
65
64
|
- vagrant-goodhosts.gemspec
|
66
|
-
homepage: https://github.com/
|
65
|
+
homepage: https://github.com/goodhosts/vagrant
|
67
66
|
licenses:
|
68
67
|
- MIT
|
69
68
|
metadata: {}
|
@@ -78,9 +77,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
77
|
version: '0'
|
79
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
79
|
requirements:
|
81
|
-
- - "
|
80
|
+
- - ">="
|
82
81
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
82
|
+
version: '0'
|
84
83
|
requirements: []
|
85
84
|
rubygems_version: 3.1.2
|
86
85
|
signing_key:
|