vagrant-goodhosts 1.0.8 → 1.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +21 -2
- data/Gemfile +4 -4
- data/README.md +17 -9
- data/Rakefile +11 -0
- data/lib/vagrant-goodhosts/Action/BaseAction.rb +39 -0
- data/lib/vagrant-goodhosts/Action/RemoveHosts.rb +2 -10
- data/lib/vagrant-goodhosts/Action/UpdateHosts.rb +2 -11
- data/lib/vagrant-goodhosts/GoodHosts.rb +50 -18
- data/lib/vagrant-goodhosts/config.rb +5 -0
- data/lib/vagrant-goodhosts/plugin.rb +4 -2
- data/lib/vagrant-goodhosts/version.rb +1 -1
- data/vagrant-goodhosts.gemspec +17 -16
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9078c31120178731d174a2aa15a12b957d3057e11816127c0f89a319c1c6a400
|
4
|
+
data.tar.gz: f6fb7224ef9ee4eca57a100eb8cafde6ef684eae61fa9aadbc1160554c6d36f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0456d61e925bbf2dbc232c4adbc3767c36722fd1f4708283201c9a654b5d972828b4cfb8c550d41b937da3fc960243f59d7e9bda8c8b4d5f8365aa1cad1db158
|
7
|
+
data.tar.gz: 91abd5a594aa8b79a605f9841725f394511907a477bf879a11cb5331d6ded560854cace147e21797c0350afed9aa44a80bae924c4caffc29a161c801b9ae2601
|
data/.gitignore
CHANGED
@@ -1,16 +1,35 @@
|
|
1
|
+
# OS-specific
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
# editors
|
5
|
+
*.swp
|
6
|
+
|
7
|
+
# Bundler/Rubygems
|
1
8
|
*.gem
|
9
|
+
.bundle
|
10
|
+
pkg/*
|
11
|
+
tags
|
12
|
+
Gemfile.lock
|
13
|
+
|
14
|
+
# Vagrant
|
15
|
+
.vagrant
|
16
|
+
Vagrantfile
|
17
|
+
!example_box/Vagrantfile
|
18
|
+
|
19
|
+
# RVM files for gemset/ruby setting
|
20
|
+
.ruby-*
|
21
|
+
.rvmrc
|
22
|
+
|
2
23
|
.idea
|
3
24
|
*.rbc
|
4
25
|
.bundle
|
5
26
|
.config
|
6
27
|
.yardoc
|
7
|
-
Gemfile.lock
|
8
28
|
InstalledFiles
|
9
29
|
_yardoc
|
10
30
|
coverage
|
11
31
|
doc/
|
12
32
|
lib/bundler/man
|
13
|
-
pkg
|
14
33
|
rdoc
|
15
34
|
spec/reports
|
16
35
|
test/tmp
|
data/Gemfile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
group :development do
|
4
|
-
gem
|
4
|
+
gem "vagrant", git: "https://github.com/hashicorp/vagrant.git"
|
5
5
|
end
|
6
6
|
|
7
7
|
group :plugins do
|
8
|
-
|
9
|
-
end
|
8
|
+
gem "vagrant-goodhosts", path: "."
|
9
|
+
end
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
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
|
-
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.
|
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
9
|
## Installation
|
10
10
|
|
@@ -38,7 +38,7 @@ This IP address and the hostname will be used for the entry in the `/etc/hosts`
|
|
38
38
|
|
39
39
|
### vagrant-hostsupdater conflicts
|
40
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.
|
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
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
43
|
|
44
44
|
### Multiple private network adapters
|
@@ -78,15 +78,24 @@ config.goodhosts.remove_on_suspend = false
|
|
78
78
|
|
79
79
|
This disables `vagrant-goodhosts` from running on **suspend** and **halt**.
|
80
80
|
|
81
|
+
### Disable file hosts clean
|
82
|
+
|
83
|
+
If you want `/etc/hosts` file cleaned add in your `VagrantFile`:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
config.goodhosts.disable_clean = false
|
87
|
+
```
|
88
|
+
|
89
|
+
This enable `vagrant-goodhosts` from running the clean command in every call.
|
81
90
|
|
82
91
|
## Suppressing prompts for elevating privileges
|
83
92
|
|
84
|
-
These prompts exist to prevent anything that is being run by the user from inadvertently updating the hosts file.
|
93
|
+
These prompts exist to prevent anything that is being run by the user from inadvertently updating the hosts file.
|
85
94
|
If you understand the risks that go with supressing them, here's how to do it.
|
86
95
|
|
87
96
|
### Linux/OS X: Passwordless sudo
|
88
97
|
|
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`.
|
98
|
+
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
99
|
The command path is printed when there are errors with sudo.
|
91
100
|
|
92
101
|
For Ubuntu and most Linux environments:
|
@@ -96,15 +105,15 @@ For Ubuntu and most Linux environments:
|
|
96
105
|
For MacOS:
|
97
106
|
|
98
107
|
%admin ALL=(root) NOPASSWD: [the-path]
|
99
|
-
|
108
|
+
|
100
109
|
Replace in both %sudo/%admin with the username it if it is not working for you.
|
101
110
|
|
102
111
|
### Windows: UAC Prompt
|
103
112
|
|
104
|
-
You can use `cacls` or `icacls` to grant your user account permanent write permission to the system's hosts file.
|
113
|
+
You can use `cacls` or `icacls` to grant your user account permanent write permission to the system's hosts file.
|
105
114
|
You have to open an elevated command prompt; hold `❖ Win` and press `X`, then choose "Command Prompt (Admin)"
|
106
115
|
|
107
|
-
cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W
|
116
|
+
cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W
|
108
117
|
|
109
118
|
## Installing The Development Version
|
110
119
|
|
@@ -113,7 +122,6 @@ If you would like to install `vagrant-goodhosts` to make contributions or change
|
|
113
122
|
```shell
|
114
123
|
git clone https://github.com/goodhosts/vagrant vagrant-goodhosts
|
115
124
|
cd vagrant-goodhosts
|
116
|
-
git checkout develop
|
117
125
|
./package.sh
|
118
126
|
vagrant plugin install vagrant-goodhosts-*.gem
|
119
127
|
```
|
data/Rakefile
CHANGED
@@ -1,3 +1,14 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
|
+
|
4
|
+
# Immediately sync all stdout so that tools like buildbot can
|
5
|
+
# immediately load in the output.
|
6
|
+
$stdout.sync = true
|
7
|
+
$stderr.sync = true
|
8
|
+
|
9
|
+
# Change to the directory of this file.
|
10
|
+
Dir.chdir(File.expand_path("../", __FILE__))
|
11
|
+
|
12
|
+
# This installs the tasks that help with gem creation and
|
13
|
+
# publishing.
|
3
14
|
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module GoodHosts
|
3
|
+
module Action
|
4
|
+
class BaseAction
|
5
|
+
include GoodHosts
|
6
|
+
|
7
|
+
# Vagrant 2.2.14 has changed the hooks execution policy so they
|
8
|
+
# started to be triggered more than once (a lot actually) which
|
9
|
+
# is non-performant and floody. With this static property, we
|
10
|
+
# control the executions and allowing just one.
|
11
|
+
#
|
12
|
+
# - https://github.com/hashicorp/vagrant/issues/12070#issuecomment-732271918
|
13
|
+
# - https://github.com/hashicorp/vagrant/compare/v2.2.13..v2.2.14#diff-4d1af7c67af870f20d303c3c43634084bab8acc101055b2e53ddc0d07f6f64dcL176-L180
|
14
|
+
# - https://github.com/goodhosts/vagrant/issues/25
|
15
|
+
@@completed = {}
|
16
|
+
|
17
|
+
def initialize(app, env)
|
18
|
+
@app = app
|
19
|
+
@machine = env[:machine]
|
20
|
+
@ui = env[:ui]
|
21
|
+
end
|
22
|
+
|
23
|
+
def call(env)
|
24
|
+
if not @@completed.key?(self.class.name)
|
25
|
+
run(env)
|
26
|
+
@@completed[self.class.name] = true
|
27
|
+
end
|
28
|
+
|
29
|
+
@app.call(env)
|
30
|
+
end
|
31
|
+
|
32
|
+
def run(env)
|
33
|
+
raise NotImplementedError.new("Must be implemented!")
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,16 +1,9 @@
|
|
1
1
|
module VagrantPlugins
|
2
2
|
module GoodHosts
|
3
3
|
module Action
|
4
|
-
class RemoveHosts
|
5
|
-
include GoodHosts
|
4
|
+
class RemoveHosts < BaseAction
|
6
5
|
|
7
|
-
def
|
8
|
-
@app = app
|
9
|
-
@machine = env[:machine]
|
10
|
-
@ui = env[:ui]
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(env)
|
6
|
+
def run(env)
|
14
7
|
machine_action = env[:machine_action]
|
15
8
|
if machine_action != :destroy || !@machine.id
|
16
9
|
if machine_action != :suspend || false != @machine.config.goodhosts.remove_on_suspend
|
@@ -22,7 +15,6 @@ module VagrantPlugins
|
|
22
15
|
end
|
23
16
|
end
|
24
17
|
end
|
25
|
-
@app.call(env)
|
26
18
|
end
|
27
19
|
|
28
20
|
end
|
@@ -1,20 +1,11 @@
|
|
1
|
-
require_relative "../GoodHosts"
|
2
1
|
module VagrantPlugins
|
3
2
|
module GoodHosts
|
4
3
|
module Action
|
5
|
-
class UpdateHosts
|
6
|
-
include GoodHosts
|
4
|
+
class UpdateHosts < BaseAction
|
7
5
|
|
8
|
-
def
|
9
|
-
@app = app
|
10
|
-
@machine = env[:machine]
|
11
|
-
@ui = env[:ui]
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
6
|
+
def run(env)
|
15
7
|
@ui.info "[vagrant-goodhosts] Checking for host entries"
|
16
8
|
addHostEntries()
|
17
|
-
@app.call(env)
|
18
9
|
end
|
19
10
|
|
20
11
|
end
|
@@ -5,10 +5,6 @@ module VagrantPlugins
|
|
5
5
|
module GoodHosts
|
6
6
|
module GoodHosts
|
7
7
|
def getIps
|
8
|
-
if Vagrant.has_plugin?("vagrant-hostsupdater")
|
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"
|
10
|
-
end
|
11
|
-
|
12
8
|
ips = []
|
13
9
|
|
14
10
|
@machine.config.vm.networks.each do |network|
|
@@ -16,7 +12,7 @@ module VagrantPlugins
|
|
16
12
|
ip = options[:ip] if (key == :private_network || key == :public_network) && options[:goodhosts] != "skip"
|
17
13
|
ips.push(ip) if ip
|
18
14
|
if options[:goodhosts] == "skip"
|
19
|
-
@ui.info '[vagrant-goodhosts]
|
15
|
+
@ui.info '[vagrant-goodhosts] Skipped adding host entries (config.vm.network goodhosts: "skip" is set)'
|
20
16
|
end
|
21
17
|
|
22
18
|
@machine.config.vm.provider :hyperv do |v|
|
@@ -36,7 +32,7 @@ module VagrantPlugins
|
|
36
32
|
end
|
37
33
|
end
|
38
34
|
|
39
|
-
|
35
|
+
|
40
36
|
end
|
41
37
|
return ips
|
42
38
|
end
|
@@ -83,21 +79,39 @@ module VagrantPlugins
|
|
83
79
|
|
84
80
|
return hostnames
|
85
81
|
end
|
82
|
+
|
83
|
+
def disableClean(ip_address)
|
84
|
+
unless ip_address.nil?
|
85
|
+
return @machine.config.goodhosts.disable_clean
|
86
|
+
end
|
87
|
+
return true
|
88
|
+
end
|
86
89
|
|
87
90
|
def addHostEntries
|
88
91
|
error = false
|
89
92
|
errorText = ""
|
90
93
|
cli = get_cli
|
91
94
|
hostnames_by_ips = generateHostnamesByIps
|
95
|
+
|
96
|
+
return if not hostnames_by_ips.any?
|
97
|
+
|
92
98
|
hostnames_by_ips.each do |ip_address, hostnames|
|
93
99
|
if ip_address.nil?
|
94
100
|
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
|
95
101
|
next
|
96
102
|
end
|
97
103
|
if cli.include? ".exe"
|
98
|
-
|
104
|
+
clean = "\"--clean\","
|
105
|
+
if disableClean(ip_address)
|
106
|
+
clean = ''
|
107
|
+
end
|
108
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"add\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
|
99
109
|
else
|
100
|
-
|
110
|
+
clean = "--clean"
|
111
|
+
if disableClean(ip_address)
|
112
|
+
clean = ''
|
113
|
+
end
|
114
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo #{cli} add #{clean} #{ip_address} #{hostnames}")
|
101
115
|
end
|
102
116
|
if !wait_thr.value.success?
|
103
117
|
error = true
|
@@ -112,15 +126,26 @@ module VagrantPlugins
|
|
112
126
|
errorText = ""
|
113
127
|
cli = get_cli
|
114
128
|
hostnames_by_ips = generateHostnamesByIps
|
129
|
+
|
130
|
+
return if not hostnames_by_ips.any?
|
131
|
+
|
115
132
|
hostnames_by_ips.each do |ip_address, hostnames|
|
116
133
|
if ip_address.nil?
|
117
134
|
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
|
118
135
|
next
|
119
136
|
end
|
120
137
|
if cli.include? ".exe"
|
121
|
-
|
138
|
+
clean = "\"--clean\","
|
139
|
+
if disableClean(ip_address)
|
140
|
+
clean = ''
|
141
|
+
end
|
142
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"remove\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
|
122
143
|
else
|
123
|
-
|
144
|
+
clean = "\"--clean\","
|
145
|
+
if disableClean(ip_address)
|
146
|
+
clean = ''
|
147
|
+
end
|
148
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo #{cli} remove #{clean} #{ip_address} #{hostnames}")
|
124
149
|
end
|
125
150
|
if !wait_thr.value.success?
|
126
151
|
error = true
|
@@ -147,25 +172,32 @@ module VagrantPlugins
|
|
147
172
|
def generateHostnamesByIps()
|
148
173
|
hostnames_by_ips = []
|
149
174
|
ips = getIps
|
175
|
+
if ips.count() < 1
|
176
|
+
return hostnames_by_ips
|
177
|
+
end
|
150
178
|
hostnames = getHostnames(ips)
|
151
179
|
if ips.count() > 1
|
152
180
|
ips.each do |ip|
|
153
181
|
ip_address = ip
|
154
|
-
hostnames[ip].
|
155
|
-
|
156
|
-
|
182
|
+
if hostnames[ip].count() > 1
|
183
|
+
hostnames[ip].each do |hostname|
|
184
|
+
if !ip_address.nil?
|
185
|
+
@ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
|
186
|
+
end
|
157
187
|
end
|
188
|
+
hostnames_by_ips = { ip_address => hostnames[ip].join(" ") }
|
158
189
|
end
|
159
|
-
hostnames_by_ips = { ip_address => hostnames[ip].join(" ") }
|
160
190
|
end
|
161
191
|
else
|
162
192
|
ip_address = ips[0]
|
163
|
-
hostnames[ip_address].
|
164
|
-
|
165
|
-
|
193
|
+
if hostnames[ip_address].count() > 1
|
194
|
+
hostnames[ip_address].each do |hostname|
|
195
|
+
if !ip_address.nil?
|
196
|
+
@ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
|
197
|
+
end
|
166
198
|
end
|
199
|
+
hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
|
167
200
|
end
|
168
|
-
hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
|
169
201
|
end
|
170
202
|
|
171
203
|
return hostnames_by_ips
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative "GoodHosts"
|
2
|
+
require_relative "Action/BaseAction"
|
3
|
+
require_relative "Action/UpdateHosts"
|
4
|
+
require_relative "Action/RemoveHosts"
|
3
5
|
|
4
6
|
module VagrantPlugins
|
5
7
|
module GoodHosts
|
data/vagrant-goodhosts.gemspec
CHANGED
@@ -3,22 +3,23 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'vagrant-goodhosts/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'vagrant-goodhosts'
|
8
|
+
s.version = VagrantPlugins::GoodHosts::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ['Daniele Scasciafratte']
|
11
|
+
s.email = ['mte90net@gmail.com']
|
12
|
+
s.description = "Enables Vagrant to update hosts file on the host machine with goodhosts"
|
13
|
+
s.summary = s.description
|
14
|
+
s.homepage = 'https://github.com/goodhosts/vagrant'
|
15
|
+
s.license = 'MIT'
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
s.files = `git ls-files`.split($/)
|
18
|
+
s.files += Dir.glob("lib/vagrant-goodhosts/bundle/*")
|
19
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
21
|
+
s.require_paths = ['lib']
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
s.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
s.add_development_dependency 'rake'
|
24
25
|
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniele Scasciafratte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- lib/vagrant-goodhosts.rb
|
54
|
+
- lib/vagrant-goodhosts/Action/BaseAction.rb
|
54
55
|
- lib/vagrant-goodhosts/Action/RemoveHosts.rb
|
55
56
|
- lib/vagrant-goodhosts/Action/UpdateHosts.rb
|
56
57
|
- lib/vagrant-goodhosts/GoodHosts.rb
|
@@ -81,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
83
84
|
requirements: []
|
84
|
-
rubygems_version: 3.2.
|
85
|
+
rubygems_version: 3.2.5
|
85
86
|
signing_key:
|
86
87
|
specification_version: 4
|
87
88
|
summary: Enables Vagrant to update hosts file on the host machine with goodhosts
|