vagrant-betterhosts 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 674b9ba6010434da286903277af9e899b2d2a982a8a4ce1434b523b460350b53
4
+ data.tar.gz: 4b635e5ddc088af98faa0c59b200fd9346b01ac0b540ca6a70375f4a01d852cb
5
+ SHA512:
6
+ metadata.gz: 38c82c8b5344f0cc3d64521746dfdf1bd987f6362468b8fece767aff2ac1a1117d78fca0f30579f331ba38b5e45ee476cdb04ca2d5387a113ac92c6a9a3f7b39
7
+ data.tar.gz: 37ead61d094950df99c39c10638bf223360d619b3fc0fbd8cc35330884486e3ac1e01d2382cc7994467eaf0b374e9ac1b8fe0a766539f79e86cf10499c94819f
data/.gitignore ADDED
@@ -0,0 +1,32 @@
1
+ # OS-specific
2
+ .DS_Store
3
+
4
+ # editors
5
+ *.swp
6
+
7
+ # Bundler/Rubygems
8
+ *.gem
9
+ .bundle
10
+ pkg/*
11
+ tags
12
+
13
+ # Vagrant
14
+ .vagrant
15
+ Vagrantfile
16
+ !example_box/Vagrantfile
17
+
18
+ *.rbc
19
+ .bundle
20
+ .config
21
+ .yardoc
22
+ InstalledFiles
23
+ _yardoc
24
+ coverage
25
+ doc/
26
+ lib/bundler/man
27
+ rdoc
28
+ spec/reports
29
+ test/tmp
30
+ test/version_tmp
31
+ tmp
32
+ bundle/
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Datasource local storage ignored files
5
+ /dataSources/
6
+ /dataSources.local.xml
7
+ # Editor-based HTTP Client requests
8
+ /httpRequests/
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.6.6" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/vagrant-betterhosts.iml" filepath="$PROJECT_DIR$/.idea/vagrant-betterhosts.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,63 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="jdk" jdkName="RVM: ruby-2.7.2 [vagrant-betterhosts]" jdkType="RUBY_SDK" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="bcrypt_pbkdf (v1.0.1, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="childprocess (v4.0.0, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.9, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="domain_name (v0.5.20190701, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="ed25519 (v1.2.4, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="erubi (v1.10.0, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="ffi (v1.15.1, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="gssapi (v1.3.1, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="gyoku (v1.3.1, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="hashicorp-checkpoint (v0.1.5, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="http-cookie (v1.0.3, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="httpclient (v2.8.3, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.10, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="listen (v3.5.1, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="little-plugger (v1.1.4, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="log4r (v1.1.10, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="logging (v2.3.0, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="mime (v0.4.4, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="mime-types (v3.3.1, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2021.0225, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="multi_json (v1.15.0, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="net-scp (v1.2.1, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="net-sftp (v3.0.0, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="net-ssh (v6.1.0, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="netrc (v0.11.0, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="nori (v2.6.0, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="rb-fsevent (v0.11.0, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="rb-inotify (v0.10.1, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="rb-kqueue (v0.2.6, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
45
+ <orderEntry type="library" scope="PROVIDED" name="rest-client (v2.0.2, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
46
+ <orderEntry type="library" scope="PROVIDED" name="ruby_dep (v1.3.1, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
47
+ <orderEntry type="library" scope="PROVIDED" name="rubyntlm (v0.6.3, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
48
+ <orderEntry type="library" scope="PROVIDED" name="rubyzip (v2.3.0, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
49
+ <orderEntry type="library" scope="PROVIDED" name="unf (v0.1.4, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
50
+ <orderEntry type="library" scope="PROVIDED" name="unf_ext (v0.0.7.7, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="vagrant (v2.2.11.dev@22795b, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
52
+ <orderEntry type="library" scope="PROVIDED" name="vagrant_cloud (v2.0.3, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
53
+ <orderEntry type="library" scope="PROVIDED" name="wdm (v0.1.1, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
54
+ <orderEntry type="library" scope="PROVIDED" name="winrm (v2.3.6, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
55
+ <orderEntry type="library" scope="PROVIDED" name="winrm-elevated (v1.2.3, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
56
+ <orderEntry type="library" scope="PROVIDED" name="winrm-fs (v1.3.5, RVM: ruby-2.7.2 [vagrant-betterhosts]) [gem]" level="application" />
57
+ </component>
58
+ <component name="RakeTasksCache">
59
+ <option name="myRootTask">
60
+ <RakeTaskImpl id="rake" />
61
+ </option>
62
+ </component>
63
+ </module>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ vagrant-betterhosts
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.7.2
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem "vagrant", git: "https://github.com/hashicorp/vagrant.git"
5
+ end
6
+
7
+ group :plugins do
8
+ gem "vagrant-betterhosts", path: "."
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,120 @@
1
+ GIT
2
+ remote: https://github.com/hashicorp/vagrant.git
3
+ revision: 22795b161bf67a4c0ebbe32c9ce8777cb888c4a7
4
+ specs:
5
+ vagrant (2.2.11.dev)
6
+ bcrypt_pbkdf (~> 1.0.0)
7
+ childprocess (~> 4.0.0)
8
+ ed25519 (~> 1.2.4)
9
+ erubi
10
+ hashicorp-checkpoint (~> 0.1.5)
11
+ i18n (~> 1.8)
12
+ listen (~> 3.1)
13
+ log4r (~> 1.1.9, < 1.1.11)
14
+ mime (~> 0.4.4)
15
+ net-scp (~> 1.2.0)
16
+ net-sftp (~> 3.0)
17
+ net-ssh (~> 6.0)
18
+ rb-kqueue (~> 0.2.0)
19
+ rest-client (>= 1.6.0, < 3.0)
20
+ ruby_dep (<= 1.3.1)
21
+ rubyzip (~> 2.0)
22
+ vagrant_cloud (~> 2.0.3)
23
+ wdm (~> 0.1.0)
24
+ winrm (>= 2.3.4, < 3.0)
25
+ winrm-elevated (>= 1.2.1, < 2.0)
26
+ winrm-fs (>= 1.3.4, < 2.0)
27
+
28
+ PATH
29
+ remote: .
30
+ specs:
31
+ vagrant-betterhosts (1.0.0)
32
+
33
+ GEM
34
+ remote: https://rubygems.org/
35
+ specs:
36
+ bcrypt_pbkdf (1.0.1)
37
+ builder (3.2.4)
38
+ childprocess (4.0.0)
39
+ concurrent-ruby (1.1.9)
40
+ domain_name (0.5.20190701)
41
+ unf (>= 0.0.5, < 1.0.0)
42
+ ed25519 (1.2.4)
43
+ erubi (1.10.0)
44
+ ffi (1.15.1)
45
+ gssapi (1.3.1)
46
+ ffi (>= 1.0.1)
47
+ gyoku (1.3.1)
48
+ builder (>= 2.1.2)
49
+ hashicorp-checkpoint (0.1.5)
50
+ http-cookie (1.0.3)
51
+ domain_name (~> 0.5)
52
+ httpclient (2.8.3)
53
+ i18n (1.8.10)
54
+ concurrent-ruby (~> 1.0)
55
+ listen (3.5.1)
56
+ rb-fsevent (~> 0.10, >= 0.10.3)
57
+ rb-inotify (~> 0.9, >= 0.9.10)
58
+ little-plugger (1.1.4)
59
+ log4r (1.1.10)
60
+ logging (2.3.0)
61
+ little-plugger (~> 1.1)
62
+ multi_json (~> 1.14)
63
+ mime (0.4.4)
64
+ mime-types (3.3.1)
65
+ mime-types-data (~> 3.2015)
66
+ mime-types-data (3.2021.0225)
67
+ multi_json (1.15.0)
68
+ net-scp (1.2.1)
69
+ net-ssh (>= 2.6.5)
70
+ net-sftp (3.0.0)
71
+ net-ssh (>= 5.0.0, < 7.0.0)
72
+ net-ssh (6.1.0)
73
+ netrc (0.11.0)
74
+ nori (2.6.0)
75
+ rb-fsevent (0.11.0)
76
+ rb-inotify (0.10.1)
77
+ ffi (~> 1.0)
78
+ rb-kqueue (0.2.6)
79
+ ffi (>= 0.5.0)
80
+ rest-client (2.0.2)
81
+ http-cookie (>= 1.0.2, < 2.0)
82
+ mime-types (>= 1.16, < 4.0)
83
+ netrc (~> 0.8)
84
+ ruby_dep (1.3.1)
85
+ rubyntlm (0.6.3)
86
+ rubyzip (2.3.0)
87
+ unf (0.1.4)
88
+ unf_ext
89
+ unf_ext (0.0.7.7)
90
+ vagrant_cloud (2.0.3)
91
+ rest-client (~> 2.0.2)
92
+ wdm (0.1.1)
93
+ winrm (2.3.6)
94
+ builder (>= 2.1.2)
95
+ erubi (~> 1.8)
96
+ gssapi (~> 1.2)
97
+ gyoku (~> 1.0)
98
+ httpclient (~> 2.2, >= 2.2.0.2)
99
+ logging (>= 1.6.1, < 3.0)
100
+ nori (~> 2.0)
101
+ rubyntlm (~> 0.6.0, >= 0.6.3)
102
+ winrm-elevated (1.2.3)
103
+ erubi (~> 1.8)
104
+ winrm (~> 2.0)
105
+ winrm-fs (~> 1.0)
106
+ winrm-fs (1.3.5)
107
+ erubi (~> 1.8)
108
+ logging (>= 1.6.1, < 3.0)
109
+ rubyzip (~> 2.0)
110
+ winrm (~> 2.0)
111
+
112
+ PLATFORMS
113
+ ruby
114
+
115
+ DEPENDENCIES
116
+ vagrant!
117
+ vagrant-betterhosts!
118
+
119
+ BUNDLED WITH
120
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright 2018 Chris Smith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # Vagrant::Betterhosts
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.
4
+
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
+
7
+ On **halt**, **destroy**, and **suspend**, those entries will be removed again. By setting the `config.betterhosts.remove_on_suspend = false`, **suspend** and **halt** will not remove them.
8
+
9
+ ## Installation
10
+
11
+ ```shell
12
+ vagrant plugin install vagrant-betterhosts
13
+ ```
14
+
15
+ To uninstall :
16
+
17
+ ```shell
18
+ vagrant plugin uninstall vagrant-betterhosts
19
+ ```
20
+
21
+ To update the plugin:
22
+
23
+ ```shell
24
+ vagrant plugin update vagrant-betterhosts
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ You currently only need the `hostname` and a `:private_network` network with a fixed IP address.
30
+
31
+ ```ruby
32
+ config.vm.network :private_network, ip: "192.168.3.10"
33
+ config.vm.hostname = "www.testing.de" # This is not used by the plugin
34
+ config.betterhosts.aliases = ["alias.testing.de", "alias2.somedomain.com"]
35
+ ```
36
+
37
+ This IP address and the hostname will be used for the entry in the `/etc/hosts` file.
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
+
44
+ ### Multiple private network adapters
45
+
46
+ If you have multiple network adapters i.e.:
47
+
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
+ ```
52
+
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.:
54
+
55
+ ```ruby
56
+ config.betterhosts.aliases = {
57
+ '10.0.0.1' => ['foo.com', 'bar.com'],
58
+ '10.0.0.2' => ['baz.com', 'bat.com']
59
+ }
60
+ ```
61
+
62
+ This will produce `/etc/hosts` entries like so:
63
+
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
+
71
+ ### Keeping Host Entries After Suspend/Halt
72
+
73
+ To keep your `/etc/hosts` file unchanged simply add the line below to your `VagrantFile`:
74
+
75
+ ```ruby
76
+ config.betterhosts.remove_on_suspend = false
77
+ ```
78
+
79
+ This disables `vagrant-betterhosts` from running on **suspend** and **halt**.
80
+
81
+ ### Disable file hosts clean
82
+
83
+ If you want `/etc/hosts` file cleaned add in your `VagrantFile`:
84
+
85
+ ```ruby
86
+ config.betterhosts.disable_clean = false
87
+ ```
88
+
89
+ This enable `vagrant-betterhosts` from running the clean command in every call.
90
+
91
+ ## Suppressing prompts for elevating privileges
92
+
93
+ These prompts exist to prevent anything that is being run by the user from inadvertently updating the hosts file.
94
+ If you understand the risks that go with supressing them, here's how to do it.
95
+
96
+ ### Linux/OS X: Passwordless sudo
97
+
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_betterhosts`.
99
+ The command path is printed when there are errors with sudo.
100
+
101
+ For Ubuntu and most Linux environments:
102
+
103
+ %sudo ALL=(root) NOPASSWD: [the-path]
104
+
105
+ For MacOS:
106
+
107
+ %admin ALL=(root) NOPASSWD: [the-path]
108
+
109
+ Replace in both %sudo/%admin with the username it if it is not working for you.
110
+
111
+ ### Windows: UAC Prompt
112
+
113
+ You can use `cacls` or `icacls` to grant your user account permanent write permission to the system's hosts file.
114
+ You have to open an elevated command prompt; hold `❖ Win` and press `X`, then choose "Command Prompt (Admin)"
115
+
116
+ cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W
117
+
118
+ ## Installing The Development Version
119
+
120
+ If you would like to install `vagrant-betterhosts` to make contributions or changes, run the following commands::
121
+
122
+ ```shell
123
+ git clone https://github.com/ajxb/vagrant-betterhosts vagrant-betterhosts
124
+ cd vagrant-betterhosts
125
+ ./package.sh
126
+ vagrant plugin install vagrant-betterhosts-*.gem
127
+ ```
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
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.
14
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,11 @@
1
+ require "vagrant-betterhosts/version"
2
+ require "vagrant-betterhosts/plugin"
3
+
4
+ module VagrantPlugins
5
+ module BetterHosts
6
+ def self.source_root
7
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,45 @@
1
+ module VagrantPlugins
2
+ module BetterHosts
3
+ module Action
4
+ class BaseAction
5
+ include BetterHosts
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
+ # Check whether the plugin has been executed for a particular
25
+ # VM as it may happen that a single Vagrantfile defines multiple
26
+ # machines and having a static flag will result in a plugin being
27
+ # executed just once.
28
+ # https://github.com/goodhosts/vagrant/issues/30
29
+ @@completed[@machine.name] = [] unless @@completed.key?(@machine.name)
30
+ unless @@completed[@machine.name].include? self.class.name
31
+ run(env)
32
+ @@completed[@machine.name] << self.class.name
33
+ end
34
+
35
+ @app.call(env)
36
+ end
37
+
38
+ def run(env)
39
+ raise NotImplementedError.new("Must be implemented!")
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ module VagrantPlugins
2
+ module BetterHosts
3
+ module Action
4
+ class RemoveHosts < BaseAction
5
+
6
+ def run(env)
7
+ machine_action = env[:machine_action]
8
+
9
+ return unless @machine.id
10
+ return unless %i[destroy halt suspend].include? machine_action
11
+
12
+ if (%i[halt suspend].include? machine_action) && (false == @machine.config.goodhosts.remove_on_suspend)
13
+ @ui.info '[vagrant-betterhosts] Removing hosts on suspend disabled'
14
+ else
15
+ @ui.info '[vagrant-betterhosts] Removing hosts'
16
+ removeHostEntries
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module VagrantPlugins
2
+ module BetterHosts
3
+ module Action
4
+ class UpdateHosts < BaseAction
5
+
6
+ def run(env)
7
+ @ui.info "[vagrant-betterhosts] Checking for host entries"
8
+ addHostEntries()
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,212 @@
1
+ require "rbconfig"
2
+ require "open3"
3
+
4
+ module VagrantPlugins
5
+ module BetterHosts
6
+ module BetterHosts
7
+ def getIps
8
+ ips = []
9
+
10
+ if @machine.config.vm.networks.length == 0
11
+ @ui.error("[vagrant-betterhosts] No ip address found for this virtual machine")
12
+ exit
13
+ end
14
+
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[:betterhosts] != "skip"
18
+ ips.push(ip) if ip
19
+ if options[:betterhosts] == "skip"
20
+ @ui.info '[vagrant-betterhosts] Skipped adding host entries (config.vm.network betterhosts: "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-betterhosts] 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
38
+ end
39
+
40
+
41
+ end
42
+ return ips
43
+ end
44
+
45
+ # https://stackoverflow.com/a/13586108/1902215
46
+ def get_os_binary
47
+ return os ||= (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
+ end
59
+
60
+ def get_cli
61
+ binary = get_os_binary
62
+ path = File.expand_path(File.dirname(File.dirname(__FILE__))) + "/vagrant-betterhosts/bundle/"
63
+ path = "#{path}#{binary}"
64
+
65
+ return path
66
+ end
67
+
68
+ # Get a hash of hostnames indexed by ip, e.g. { 'ip1': ['host1'], 'ip2': ['host2', 'host3'] }
69
+ def getHostnames(ips)
70
+ hostnames = Hash.new { |h, k| h[k] = [] }
71
+
72
+ case @machine.config.betterhosts.aliases
73
+ when Array
74
+ # simple list of aliases to link to all ips
75
+ ips.each do |ip|
76
+ hostnames[ip] += @machine.config.betterhosts.aliases
77
+ end
78
+ when Hash
79
+ # complex definition of aliases for various ips
80
+ @machine.config.betterhosts.aliases.each do |ip, hosts|
81
+ hostnames[ip] += Array(hosts)
82
+ end
83
+ end
84
+
85
+ return hostnames
86
+ end
87
+
88
+ def disableClean(ip_address)
89
+ unless ip_address.nil?
90
+ return @machine.config.betterhosts.disable_clean
91
+ end
92
+ return true
93
+ end
94
+
95
+ def addHostEntries
96
+ error = false
97
+ errorText = ""
98
+ cli = get_cli
99
+ hostnames_by_ips = generateHostnamesByIps
100
+
101
+ return if not hostnames_by_ips.any?
102
+
103
+ hostnames_by_ips.each do |ip_address, hostnames|
104
+ if ip_address.nil?
105
+ @ui.error "[vagrant-betterhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
106
+ next
107
+ end
108
+ if cli.include? ".exe"
109
+ clean = "\"--clean\","
110
+ if disableClean(ip_address)
111
+ clean = ''
112
+ end
113
+ stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"add\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
114
+ else
115
+ clean = "--clean"
116
+ if disableClean(ip_address)
117
+ clean = ''
118
+ end
119
+ stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' add #{clean} #{ip_address} #{hostnames}")
120
+ end
121
+ if !wait_thr.value.success?
122
+ error = true
123
+ errorText = stderr.read.strip
124
+ end
125
+ end
126
+ printReadme(error, errorText)
127
+ end
128
+
129
+ def removeHostEntries
130
+ error = false
131
+ errorText = ""
132
+ cli = get_cli
133
+ hostnames_by_ips = generateHostnamesByIps
134
+
135
+ return if not hostnames_by_ips.any?
136
+
137
+ hostnames_by_ips.each do |ip_address, hostnames|
138
+ if ip_address.nil?
139
+ @ui.error "[vagrant-betterhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
140
+ next
141
+ end
142
+ if cli.include? ".exe"
143
+ clean = "\"--clean\","
144
+ if disableClean(ip_address)
145
+ clean = ''
146
+ end
147
+ stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"remove\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
148
+ else
149
+ clean = "\"--clean\","
150
+ if disableClean(ip_address)
151
+ clean = ''
152
+ end
153
+ stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' remove #{clean} #{ip_address} #{hostnames}")
154
+ end
155
+ if !wait_thr.value.success?
156
+ error = true
157
+ errorText = stderr.read.strip
158
+ end
159
+ end
160
+ printReadme(error, errorText)
161
+ end
162
+
163
+ def printReadme(error, errorText)
164
+ if error
165
+ cli = get_cli
166
+ @ui.error "[vagrant-betterhosts] Issue executing goodhosts CLI: #{errorText}"
167
+ @ui.error "[vagrant-betterhosts] Cli path: #{cli}"
168
+ if cli.include? ".exe"
169
+ @ui.error "[vagrant-betterhosts] Check the readme at https://github.com/ajxb/vagrant-betterhosts#windows-uac-prompt"
170
+ exit
171
+ else
172
+ @ui.error "[vagrant-betterhosts] Check the readme at https://github.com/ajxb/vagrant-betterhosts#passwordless-sudo"
173
+ end
174
+ end
175
+ end
176
+
177
+ def generateHostnamesByIps()
178
+ hostnames_by_ips = []
179
+ ips = getIps
180
+ if ips.count() < 1
181
+ return hostnames_by_ips
182
+ end
183
+ hostnames = getHostnames(ips)
184
+ if ips.count() > 1
185
+ ips.each do |ip|
186
+ ip_address = ip
187
+ if hostnames[ip].count() > 0
188
+ hostnames[ip].each do |hostname|
189
+ if !ip_address.nil?
190
+ @ui.info "[vagrant-betterhosts] - found entry for: #{ip_address} #{hostname}"
191
+ end
192
+ end
193
+ hostnames_by_ips = { ip_address => hostnames[ip].join(" ") }
194
+ end
195
+ end
196
+ else
197
+ ip_address = ips[0]
198
+ if hostnames[ip_address].count() > 0
199
+ hostnames[ip_address].each do |hostname|
200
+ if !ip_address.nil?
201
+ @ui.info "[vagrant-betterhosts] - found entry for: #{ip_address} #{hostname}"
202
+ end
203
+ end
204
+ hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
205
+ end
206
+ end
207
+
208
+ return hostnames_by_ips
209
+ end
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,17 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module BetterHosts
5
+ class Config < Vagrant.plugin("2", :config)
6
+ attr_accessor :aliases
7
+ attr_accessor :id
8
+ attr_accessor :remove_on_suspend
9
+ attr_accessor :disable_clean
10
+
11
+ def initialize
12
+ @remove_on_suspend = true
13
+ @disable_clean = true
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ require_relative "BetterHosts"
2
+ require_relative "Action/BaseAction"
3
+ require_relative "Action/UpdateHosts"
4
+ require_relative "Action/RemoveHosts"
5
+
6
+ module VagrantPlugins
7
+ module BetterHosts
8
+ class Plugin < Vagrant.plugin('2')
9
+ name 'BetterHosts'
10
+ description <<-DESC
11
+ This plugin manages the /etc/hosts file for the host machine. An entry is
12
+ created for the hostname attribute in the vm.config.
13
+ DESC
14
+
15
+ config(:betterhosts) do
16
+ require_relative 'config'
17
+ Config
18
+ end
19
+
20
+ action_hook(:betterhosts, :machine_action_up) do |hook|
21
+ hook.append(Action::UpdateHosts)
22
+ end
23
+
24
+ action_hook(:betterhosts, :machine_action_provision) do |hook|
25
+ hook.before(Vagrant::Action::Builtin::Provision, Action::UpdateHosts)
26
+ end
27
+
28
+ action_hook(:betterhosts, :machine_action_halt) do |hook|
29
+ hook.append(Action::RemoveHosts)
30
+ end
31
+
32
+ action_hook(:betterhosts, :machine_action_suspend) do |hook|
33
+ hook.append(Action::RemoveHosts)
34
+ end
35
+
36
+ action_hook(:betterhosts, :machine_action_destroy) do |hook|
37
+ hook.append(Action::RemoveHosts)
38
+ end
39
+
40
+ action_hook(:betterhosts, :machine_action_reload) do |hook|
41
+ hook.prepend(Action::RemoveHosts)
42
+ hook.append(Action::UpdateHosts)
43
+ end
44
+
45
+ action_hook(:betterhosts, :machine_action_resume) do |hook|
46
+ hook.prepend(Action::RemoveHosts)
47
+ hook.append(Action::UpdateHosts)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module BetterHosts
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
data/package.sh ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env bash
2
+
3
+ mkdir -p ./lib/vagrant-betterhosts/bundle
4
+ cd ./lib/vagrant-betterhosts/bundle
5
+ # Download
6
+ curl -s https://api.github.com/repos/goodhosts/cli/releases/latest | jq --raw-output '.assets[] | .browser_download_url' | xargs wget -i
7
+ # Extract
8
+ tar -zxvf goodhosts_darwin_amd64.tar.gz goodhosts && mv goodhosts cli_osx
9
+ tar -zxvf goodhosts_linux_amd64.tar.gz goodhosts && mv goodhosts cli
10
+ tar -zxvf goodhosts_windows_amd64.tar.gz goodhosts.exe && mv goodhosts.exe cli.exe
11
+ rm -f ./*.tar.gz
12
+ rm -f ./*.txt
13
+ # Generate
14
+ cd ../../../
15
+ gem build vagrant-betterhosts.gemspec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-betterhosts/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'vagrant-betterhosts'
8
+ s.version = VagrantPlugins::BetterHosts::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ['Adam Butler']
11
+ s.email = ['adam.j.butler@protonmail.com']
12
+ s.description = 'Enables Vagrant to update hosts file on the host machine using the goodhosts cli tool'
13
+ s.summary = 'Vagrant plugin to manage the hosts file on the host machine'
14
+ s.homepage = 'https://github.com/ajxb/vagrant-betterhosts'
15
+ s.license = 'MIT'
16
+
17
+ s.required_ruby_version = "~> 2.5", "< 2.8"
18
+ s.files = `git ls-files`.split($/)
19
+ s.files += Dir.glob("lib/vagrant-betterhosts/bundle/*")
20
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
22
+ s.require_paths = ['lib']
23
+
24
+ s.add_development_dependency 'bundler', '~> 1.3'
25
+ s.add_development_dependency 'rake', '~> 13.0'
26
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-betterhosts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Butler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ description: Enables Vagrant to update hosts file on the host machine using the goodhosts
42
+ cli tool
43
+ email:
44
+ - adam.j.butler@protonmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".idea/.gitignore"
51
+ - ".idea/misc.xml"
52
+ - ".idea/modules.xml"
53
+ - ".idea/vagrant-betterhosts.iml"
54
+ - ".idea/vcs.xml"
55
+ - ".ruby-gemset"
56
+ - ".ruby-version"
57
+ - Gemfile
58
+ - Gemfile.lock
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - lib/vagrant-betterhosts.rb
63
+ - lib/vagrant-betterhosts/Action/BaseAction.rb
64
+ - lib/vagrant-betterhosts/Action/RemoveHosts.rb
65
+ - lib/vagrant-betterhosts/Action/UpdateHosts.rb
66
+ - lib/vagrant-betterhosts/BetterHosts.rb
67
+ - lib/vagrant-betterhosts/bundle/cli
68
+ - lib/vagrant-betterhosts/bundle/cli.exe
69
+ - lib/vagrant-betterhosts/bundle/cli_osx
70
+ - lib/vagrant-betterhosts/config.rb
71
+ - lib/vagrant-betterhosts/plugin.rb
72
+ - lib/vagrant-betterhosts/version.rb
73
+ - package.sh
74
+ - vagrant-betterhosts.gemspec
75
+ homepage: https://github.com/ajxb/vagrant-betterhosts
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '2.5'
88
+ - - "<"
89
+ - !ruby/object:Gem::Version
90
+ version: '2.8'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.1.4
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Vagrant plugin to manage the hosts file on the host machine
101
+ test_files: []