vagrant-goodhosts 1.0.7 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 773499e5908599b791ece8dbfbeb82929508e5c9341af2603250e0d973ab1be2
4
- data.tar.gz: 4b65f0a08a6779474a320e40ef0a0b924bb51c7c3334fa53a182da3dc856d5aa
3
+ metadata.gz: e0a9a9277945173d86017e1adc047ab0f77c2cc1779720feacab37f2095eeaab
4
+ data.tar.gz: 20814631c5aea07c8eb72a7ea7458ef0e6617ce5358585587a62883c30cee311
5
5
  SHA512:
6
- metadata.gz: d71b200fa955218bdf800fc4da2d5c56d3b3d8719145b9961e8d9017d3215a34b21753dc4b10e151ca2616e05e24e0709a14d2058ba4b84da5ff1a9dbeb2d06e
7
- data.tar.gz: d9ff6081767d318a1c91d96bf683c4791a809c60ec6e6d0fb39abc541d4e647dc50789717471493be2e8862ceda89718f33cb57e07804d4a3d1f6f71f5190cd2
6
+ metadata.gz: 8ff28f24b53144938296b34731d73f0569724b4d2bd877ef5e1d148a4a485de2c2aefe34abaecdd60ba9a3a6d3c24296d3a21ddebe42864e32dfa459083ec19b
7
+ data.tar.gz: 11c2e604dace4cc0cb75a829f0162d0a3a9941f14ba9103fc79333ee87d4eab107c659c463ff4fe3fa19395549a6089e56fda12256da95a9abd6e627e5ba8712
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 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  group :development do
4
- gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.6.2'
4
+ gem "vagrant", git: "https://github.com/hashicorp/vagrant.git"
5
5
  end
6
6
 
7
7
  group :plugins do
8
- gemspec
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
@@ -3,6 +3,7 @@ module VagrantPlugins
3
3
  module Action
4
4
  class RemoveHosts
5
5
  include GoodHosts
6
+ @@updated = false
6
7
 
7
8
  def initialize(app, env)
8
9
  @app = app
@@ -14,11 +15,14 @@ module VagrantPlugins
14
15
  machine_action = env[:machine_action]
15
16
  if machine_action != :destroy || !@machine.id
16
17
  if machine_action != :suspend || false != @machine.config.goodhosts.remove_on_suspend
17
- if machine_action != :halt || false != @machine.config.goodhosts.remove_on_suspend
18
- @ui.info "[vagrant-goodhosts] Removing hosts"
19
- removeHostEntries
20
- else
21
- @ui.info "[vagrant-goodhosts] Removing hosts on suspend disabled"
18
+ unless @@updated
19
+ @@updated = true
20
+ if machine_action != :halt || false != @machine.config.goodhosts.remove_on_suspend
21
+ @ui.info "[vagrant-goodhosts] Removing hosts"
22
+ removeHostEntries
23
+ else
24
+ @ui.info "[vagrant-goodhosts] Removing hosts on suspend disabled"
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -4,6 +4,7 @@ module VagrantPlugins
4
4
  module Action
5
5
  class UpdateHosts
6
6
  include GoodHosts
7
+ @@updated = false
7
8
 
8
9
  def initialize(app, env)
9
10
  @app = app
@@ -12,8 +13,11 @@ module VagrantPlugins
12
13
  end
13
14
 
14
15
  def call(env)
15
- @ui.info "[vagrant-goodhosts] Checking for host entries"
16
- addHostEntries()
16
+ unless @@updated
17
+ @@updated = true
18
+ @ui.info "[vagrant-goodhosts] Checking for host entries"
19
+ addHostEntries()
20
+ end
17
21
  @app.call(env)
18
22
  end
19
23
 
@@ -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] Skipping adding host entries (config.vm.network goodhosts: "skip" is set)'
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
- stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "add", "--clean", ip_address, hostnames)
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
- stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "add", "--clean", ip_address, hostnames)
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
- stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "remove", "--clean", ip_address, hostnames)
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
- stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "remove", "--clean", ip_address, hostnames)
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].each do |hostname|
155
- if !ip_address.nil?
156
- @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
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].each do |hostname|
164
- if !ip_address.nil?
165
- @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
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
@@ -6,6 +6,11 @@ module VagrantPlugins
6
6
  attr_accessor :aliases
7
7
  attr_accessor :id
8
8
  attr_accessor :remove_on_suspend
9
+ attr_accessor :disable_clean
10
+
11
+ def initialize
12
+ @disable_clean = true
13
+ end
9
14
  end
10
15
  end
11
16
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module GoodHosts
3
- VERSION = '1.0.7'
3
+ VERSION = '1.0.12'
4
4
  end
5
5
  end
@@ -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 |spec|
7
- spec.name = 'vagrant-goodhosts'
8
- spec.version = VagrantPlugins::GoodHosts::VERSION
9
- spec.authors = ['Daniele Scasciafratte']
10
- spec.email = ['mte90net@gmail.com']
11
- spec.description = %q{Enables Vagrant to update hosts file on the host machine with goodhosts}
12
- spec.summary = spec.description
13
- spec.homepage = 'https://github.com/goodhosts/vagrant'
14
- spec.license = 'MIT'
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
- spec.files = `git ls-files`.split($/)
17
- spec.files += Dir.glob("lib/vagrant-goodhosts/bundle/*")
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ['lib']
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
- spec.add_development_dependency 'bundler', '~> 1.3'
23
- spec.add_development_dependency 'rake'
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.7
4
+ version: 1.0.12
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-10-19 00:00:00.000000000 Z
11
+ date: 2021-01-18 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.2.0.rc.1
84
+ rubygems_version: 3.2.5
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: Enables Vagrant to update hosts file on the host machine with goodhosts