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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13ef1e50681184f9636c42cb63ef886051aab4f19c388f913f81e3ccee5c9c61
4
- data.tar.gz: 60da586ec22b7387b3b7ca20641ec49316e3ecd4ed10e672c82fc48f1c8bb8d0
3
+ metadata.gz: 7d08aeb238e55a6b9c10399ed2bb6cdf227e223bbde08e4a6dfb11366e67e5ee
4
+ data.tar.gz: 59169325206bd3f62a0b040d259fe14dc42dd3fa310822e5bccd4fc04beb15c0
5
5
  SHA512:
6
- metadata.gz: f140337609b3baae16139812a8013c7bb2396765340db63b8bb8ad740a115ee62fc089327bf9366113029cbc17419b418cc1309c5cfa176e0f863298ac5b75e0
7
- data.tar.gz: da008e6cc94397d22242e2b75a5d4c3e15c9c6d0cc7bc7a4a3b508361572304ab0a949211dea4430ce1b5c7b3f68cf8ee3b8f213dac9043d50715953b34025f2
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 an entry to your /etc/hosts file on the host system using [GoodHosts](https://github.com/goodhosts/cli). This plugin is based on [vagrant-hostsupdater](https://github.com/cogitatio/vagrant-hostsupdater) 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
- On **up**, **resume** and **reload** commands, it tries to add the information, if it does not already exist in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file.
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
- $ vagrant plugin install vagrant-goodhosts
11
+ ```shell
12
+ vagrant plugin install vagrant-goodhosts
13
+ ```
14
14
 
15
- Uninstall it with:
15
+ To uninstall :
16
16
 
17
- $ vagrant plugin uninstall vagrant-goodhosts
17
+ ```shell
18
+ vagrant plugin uninstall vagrant-goodhosts
19
+ ```
18
20
 
19
- Update the plugin with:
21
+ To update the plugin:
20
22
 
21
- $ vagrant plugin update vagrant-goodhosts
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
- config.vm.network :private_network, ip: "192.168.3.10"
28
- config.vm.hostname = "www.testing.de"
29
- config.goodhosts.aliases = ["alias.testing.de", "alias2.somedomain.com"]
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
- config.vm.network :private_network, ip: "10.0.0.1"
38
- config.vm.network :private_network, ip: "10.0.0.2"
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
- 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.:
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
- config.goodhosts.aliases = {
43
- '10.0.0.1' => ['foo.com', 'bar.com'],
44
- '10.0.0.2' => ['baz.com', 'bat.com']
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
- 10.0.0.1 foo.com
50
- 10.0.0.1 bar.com
51
- 10.0.0.2 baz.com
52
- 10.0.0.2 bat.com
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 /etc/hosts file unchanged simply add the line below to your `VagrantFile`:
73
+ To keep your `/etc/hosts` file unchanged simply add the line below to your `VagrantFile`:
57
74
 
58
- config.goodhosts.remove_on_suspend = false
59
-
60
- This disables vagrant-goodhosts from running on **suspend** and **halt**.
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
- Change the cli path as printed in the vagrant output.
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 development version
109
+ ## Installing The Development Version
89
110
 
90
- If you would like to install vagrant-goodhosts on the development version perform the following:
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 '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 "The Vagrant plugin vagrant-hostsupdater is installed but is executed always also when is not configured in your Vagrantfile!"
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("Waiting for the machine to report its IP address(might take some time, have a 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'] }
@@ -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
- 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
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
- 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
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
- cli = get_cli
153
- @ui.error "[vagrant-goodhosts] Issue on executing goodhosts: #{errorText}"
154
- @ui.error "[vagrant-goodhosts] Cli path: #{cli}"
155
- @ui.error "[vagrant-goodhosts] Check the readme at https://github.com/Mte90/vagrant-goodhosts#passwordless-sudo"
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
@@ -44,11 +44,6 @@ module VagrantPlugins
44
44
  hook.prepend(Action::RemoveHosts)
45
45
  hook.append(Action::UpdateHosts)
46
46
  end
47
-
48
- command(:goodhosts) do
49
- require_relative 'command'
50
- Command
51
- end
52
47
  end
53
48
  end
54
49
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module GoodHosts
3
- VERSION = '1.0.0-beta4'
3
+ VERSION = '1.0.4'
4
4
  end
5
5
  end
@@ -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/mte90/vagrant-goodhosts'
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.0.pre.beta4
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-06-05 00:00:00.000000000 Z
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/mte90/vagrant-goodhosts
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: 1.3.1
82
+ version: '0'
84
83
  requirements: []
85
84
  rubygems_version: 3.1.2
86
85
  signing_key:
@@ -1,10 +0,0 @@
1
- module VagrantPlugins
2
- module GoodHosts
3
- class Command < Vagrant.plugin('2', :command)
4
-
5
- def execute
6
- puts "ran command"
7
- end
8
- end
9
- end
10
- end