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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dae3311603bb8549e1be6f3eb18b46c0c0fd7b1fab7d6c43f42c190fac1dd907
4
- data.tar.gz: 168d43266f469c5ba81ebac4ebe6933b0500123cf7809d7276567709bf794bf6
3
+ metadata.gz: 77a1b25e87a6f494d365411f2094bf55b3bb44d52a760aea2cccf81147f326f2
4
+ data.tar.gz: a8212f3941c4fd3e55ddc6ce50c1d0a92fb892bf94f2be58f71b89d817c1f972
5
5
  SHA512:
6
- metadata.gz: 354b9a2a3945f1ebcf3ba8b7877d6e2bf553a14dcfbd85d140f81dda081fad7c1162eef5e354ad2024d516ac2b31b5641066ac8ff110737248be2699f8c42b04
7
- data.tar.gz: 5a46c36236e3933caa25185420f2b055d2c01ae1f73236f5708e53f7f4cec4c45b90d11be1fe48cd219af5a349b23d33361781dc9fed83838ba32f45866093d6
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
- Change the cli path as printed in the vagrant output.
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
 
@@ -5,7 +5,6 @@ module VagrantPlugins
5
5
  class UpdateHosts
6
6
  include GoodHosts
7
7
 
8
-
9
8
  def initialize(app, env)
10
9
  @app = app
11
10
  @machine = env[:machine]
@@ -1,69 +1,67 @@
1
- require 'rbconfig'
2
- require 'open3'
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
- @ui.error "[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"
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
- @machine.config.vm.networks.each do |network|
16
- key, options = network[0], network[1]
17
- ip = options[:ip] if (key == :private_network || key == :public_network) && options[:goodhosts] != "skip"
18
- ips.push(ip) if ip
19
- if options[:goodhosts] == 'skip'
20
- @ui.info '[vagrant-goodhosts] Skipping adding host entries (config.vm.network goodhosts: "skip" is set)'
21
- end
22
-
23
- @machine.config.vm.provider :hyperv do |v|
24
- timeout = @machine.provider_config.ip_address_timeout
25
- @ui.output("[vagrant-goodhosts] Waiting for the guest machine to report its IP address ( this might take some time, have patience )...")
26
- @ui.detail("Timeout: #{timeout} seconds")
27
-
28
- options = {
29
- vmm_server_address: @machine.provider_config.vmm_server_address,
30
- proxy_server_address: @machine.provider_config.proxy_server_address,
31
- timeout: timeout,
32
- machine: @machine
33
- }
34
- network = @machine.provider.driver.read_guest_ip(options)
35
- if network["ip"]
36
- ips.push( network["ip"] ) unless ips.include? network["ip"]
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
- return ips
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 get_OS
46
- return os ||= (
47
- host_os = RbConfig::CONFIG['host_os']
48
- case host_os
49
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
50
- :'cli.exe'
51
- when /darwin|mac os/
52
- :'cli_osx'
53
- when /linux/
54
- :'cli'
55
- else
56
- raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
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
- cli = get_OS
63
- path = File.expand_path(File.dirname(File.dirname(__FILE__))) + '/vagrant-goodhosts/bundle/'
64
- path = "#{path}#{cli}"
65
-
66
- return path
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
- ips.each do |ip|
105
- hostnames[ip].each do |hostname|
106
- ip_address = ip
107
- if !ip_address.nil?
108
- @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
109
- if cli.include? ".exe"
110
- stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "a", ip_address, hostname)
111
- else
112
- stdin, stdout, stderr, wait_thr = Open3.popen3('sudo', cli, "a", ip_address, hostname)
113
- end
114
- if !wait_thr.value.success?
115
- error = true
116
- errorText = stderr.read.strip
117
- end
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
- ips.each do |ip|
131
- hostnames[ip].each do |hostname|
132
- ip_address = ip
133
- if !ip_address.nil?
134
- @ui.info "[vagrant-goodhosts] - remove entry for: #{ip_address} #{hostname}"
135
- if cli.include? ".exe"
136
- stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "r", ip_address, hostname)
137
- else
138
- stdin, stdout, stderr, wait_thr = Open3.popen3('sudo', cli, "r", ip_address, hostname)
139
- end
140
- if !wait_thr.value.success?
141
- error = true
142
- errorText = stderr.read.strip
143
- end
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
- cli = get_cli
153
- @ui.error "[vagrant-goodhosts] Issue executing goodhosts CLI: #{errorText}"
154
- @ui.error "[vagrant-goodhosts] Cli path: #{cli}"
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
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module GoodHosts
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.6'
4
4
  end
5
5
  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.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-06-08 00:00:00.000000000 Z
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.2
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