vagrant-hostsupdater 0.0.11 → 1.0.0

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
  SHA1:
3
- metadata.gz: 51ccd0d56a1d0868f7dd00c567834fc5292e51b6
4
- data.tar.gz: 0309736e690639b86ce559d0d6530d2e82c3ffdf
3
+ metadata.gz: aa5a906b2206c4c30ffc719ea0b078317cd884c8
4
+ data.tar.gz: a8f1c3bd95b09e2d604a11a3c9281c904edeedc4
5
5
  SHA512:
6
- metadata.gz: 41c2785d873b31de816a03dce41460927634c033e92c8250f1d62c84b25181db1f9d149d2e7920fdf0f0c3ac07fc792e0270fc8e667617439807fda3b9b65f77
7
- data.tar.gz: 3c9b5067f24205f92e7e0a906fcd384e67004d08b3c626958bd41cc5d24c37377f531d1f4c592c45019f233eea44d05c819dc2d8b103e36b6010112a5a803d8b
6
+ metadata.gz: dbe7a6d519649649a9373b618176d13871fb442d2be630bb29fefe980bb5bbacabf3108d3a779bab82de53c460b61e1e77cae722940461913ad0ec072d17d4dd
7
+ data.tar.gz: d004fb3ec7fde2201ae3b0eb67470cb4ae853c95b587b37536456ed788ccba65a6ce6aff686be481eff64e0287c96519878008cefe9193aba2ebf2bd20031d08
data/Gemfile CHANGED
@@ -1,50 +1,9 @@
1
- $:.unshift File.expand_path("../lib", __FILE__)
1
+ source 'https://rubygems.org'
2
2
 
3
- Gem::Specification.new do |s|
4
- s.name = "vagrant-hostsupdater"
5
- s.version = 0.2
6
- s.platform = Gem::Platform::RUBY
7
- s.authors = "Falk Kühnel"
8
- s.email = "fk@cogitatio.de"
9
- s.homepage = "https://github.com/cogitatio/vagrant-hostsupdater"
10
- s.summary = "Enables Vagrant to update hosts file on the host machine"
11
- s.description = "Enables Vagrant to update hosts file on the host machine"
12
-
13
-
14
- # s.add_development_dependency "rake"
15
-
16
- # # The following block of code determines the files that should be included
17
- # # in the gem. It does this by reading all the files in the directory where
18
- # # this gemspec is, and parsing out the ignored files from the gitignore.
19
- # # Note that the entire gitignore(5) syntax is not supported, specifically
20
- # # the "!" syntax, but it should mostly work correctly.
21
- # root_path = File.dirname(__FILE__)
22
- # all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
23
- # all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
24
- # gitignore_path = File.join(root_path, ".gitignore")
25
- # gitignore = File.readlines(gitignore_path)
26
- # gitignore.map! { |line| line.chomp.strip }
27
- # gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
28
-
29
- # unignored_files = all_files.reject do |file|
30
- # # Ignore any directories, the gemspec only cares about files
31
- # next true if File.directory?(file)
32
-
33
- # # Ignore any paths that match anything in the gitignore. We do
34
- # # two tests here:
35
- # #
36
- # # - First, test to see if the entire path matches the gitignore.
37
- # # - Second, match if the basename does, this makes it so that things
38
- # # like '.DS_Store' will match sub-directories too (same behavior
39
- # # as git).
40
- # #
41
- # gitignore.any? do |ignore|
42
- # File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
43
- # File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
44
- # end
45
- # end
46
-
47
- # s.files = unignored_files
48
- # s.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
49
- # s.require_path = 'lib'
3
+ group :development do
4
+ gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.6.2'
50
5
  end
6
+
7
+ group :plugins do
8
+ gemspec
9
+ end
data/README.md CHANGED
@@ -1,14 +1,19 @@
1
1
  # Vagrant::Hostsupdater
2
2
 
3
- This plugin adds an entry to your /etc/hosts file on the host system.
3
+ [![Gem Version](https://badge.fury.io/rb/vagrant-hostsupdater.svg)](https://badge.fury.io/rb/vagrant-hostsupdater)
4
+ [![Gem](https://img.shields.io/gem/dt/vagrant-hostsupdater.svg)](https://rubygems.org/gems/vagrant-hostsupdater)
5
+ [![Gem](https://img.shields.io/gem/dtv/vagrant-hostsupdater.svg)](https://rubygems.org/gems/vagrant-hostsupdater)
4
6
 
5
- On **up**, **resume** and **reload** commands, it tries to add the information, if its not already existant 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.
7
+ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cogitatio/vagrant-hostsupdater?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
8
+ [![Twitter](https://img.shields.io/twitter/url/https/github.com/cogitatio/vagrant-hostsupdater.svg?style=social)](https://twitter.com/intent/tweet?text=Checkout%20this%20awesome%20Vagrant%20plugin!&url=https%3A%2F%2Fgithub.com%2Fcogiatio%2Fvagrant-hostsupdater&hashtags=hostsupdater,vagrant)
6
9
 
7
- On **halt** and **destroy**, those entries will be removed again.
8
- By setting the remove\_on\_suspend option, you can have them removed on **suspend**, too:
9
10
 
10
- config.hostsupdater.remove_on_suspend = true
11
+ This plugin adds an entry to your /etc/hosts file on the host system.
12
+
13
+ On **up**, **resume** and **reload** commands, it tries to add the information, if its not already existant 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.
11
14
 
15
+ On **halt**, **destroy**, and **suspend**, those entries will be removed again.
16
+ By setting the `config.hostsupdater.remove_on_suspend = false`, **suspend** will not remove them.
12
17
 
13
18
 
14
19
  ## Installation
@@ -19,17 +24,80 @@ Uninstall it with:
19
24
 
20
25
  $ vagrant plugin uninstall vagrant-hostsupdater
21
26
 
27
+ Update the plugin with:
28
+
29
+ $ vagrant plugin update vagrant-hostsupdater
30
+
22
31
  ## Usage
23
32
 
24
- At the moment, the only things you need, are the hostname and a :private_network network with a fixed ip.
33
+ You currently only need the `hostname` and a `:private_network` network with a fixed IP address.
25
34
 
26
35
  config.vm.network :private_network, ip: "192.168.3.10"
27
36
  config.vm.hostname = "www.testing.de"
28
37
  config.hostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"]
29
38
 
30
- This ip and the hostname will be used for the entry in the /etc/hosts file.
39
+ This IP address and the hostname will be used for the entry in the `/etc/hosts` file.
40
+
41
+ ### Skipping hostupdater
42
+
43
+ To skip adding some entries to the /etc/hosts file add `hostsupdater: "skip"` option to network configuration:
31
44
 
32
- ## Versions
45
+ config.vm.network "private_network", ip: "172.21.9.9", hostsupdater: "skip"
46
+
47
+ Example:
48
+
49
+ config.vm.network :private_network, ip: "192.168.50.4"
50
+ config.vm.network :private_network,
51
+ ip: "172.21.9.9",
52
+ netmask: "255.255.240.0",
53
+ hostsupdater: "skip"
54
+
55
+
56
+ ## Passwordless sudo
57
+
58
+ Add the following snippet to the sudoers file (for example, to `/etc/sudoers.d/vagrant_hostupdater`) to make it
59
+ stop asking password when updating hosts file:
60
+
61
+ # Allow passwordless startup of Vagrant with vagrant-hostsupdater.
62
+ Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts
63
+ Cmnd_Alias VAGRANT_HOSTS_REMOVE = /usr/bin/sed -i -e /*/ d /etc/hosts
64
+ %sudo ALL=(root) NOPASSWD: VAGRANT_HOSTS_ADD, VAGRANT_HOSTS_REMOVE
65
+
66
+
67
+ ## Installing development version
68
+
69
+ If you would like to install vagrant-hostsupdater on the development version perform the following:
70
+
71
+ ```
72
+ git clone https://github.com/cogitatio/vagrant-hostsupdater
73
+ cd vagrant-hostsupdater
74
+ git checkout develop
75
+ gem build vagrant-hostsupdater.gemspec
76
+ vagrant plugin install vagrant-hostsupdater-*.gem
77
+ ```
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create new Pull Request on the `develop` branch
86
+
87
+
88
+ ## Versions
89
+
90
+ ### 1.0.0
91
+ * Stable release
92
+ * Feature: Added `skip` flag [#69](/../../issues/69)
93
+ * Feature: Hosts update on provision action [#65](/../../issues/65)
94
+ * Bugfix: `remove_on_suspend` should be true [#19](/../../issues/19)
95
+ * Bugfix: Line break not inserted before first host [#37](/../../issues/37)
96
+ * Bugfix: Old changes not removed in linux [#67](/../../issues/67)
97
+ * Bugfix: Writable issue on OSX [#47](/../../issues/47)
98
+ * Bugfix: Update hosts before provisioning [#31](/../../issues/31)
99
+ * Misc: Using Semantic Versioning for version number
100
+ * Misc: Added note regarding sudoers file
33
101
 
34
102
  ### 0.0.11
35
103
  * bugfix: Fix additional new lines being added to hosts file (Thanks to vincentmac)
@@ -57,13 +125,4 @@ This ip and the hostname will be used for the entry in the /etc/hosts file.
57
125
  * fixed problem with removing hosts entries on destroy command (Thanks to Andy Bohne)
58
126
 
59
127
  ### 0.0.3
60
- * added aliases config option to define additional hostnames
61
-
62
-
63
- ## Contributing
64
-
65
- 1. Fork it
66
- 2. Create your feature branch (`git checkout -b my-new-feature`)
67
- 3. Commit your changes (`git commit -am 'Add some feature'`)
68
- 4. Push to the branch (`git push origin my-new-feature`)
69
- 5. Create new Pull Request
128
+ * added aliases config option to define additional hostnames
@@ -13,7 +13,7 @@ module VagrantPlugins
13
13
  def call(env)
14
14
  machine_action = env[:machine_action]
15
15
  if machine_action != :destroy || !@machine.id
16
- if machine_action != :suspend || @machine.config.hostsupdater.remove_on_suspend
16
+ if machine_action != :suspend || false != @machine.config.hostsupdater.remove_on_suspend
17
17
  @ui.info "Removing hosts"
18
18
  removeHostEntries
19
19
  else
@@ -14,8 +14,8 @@ module VagrantPlugins
14
14
 
15
15
  def call(env)
16
16
  @ui.info "Checking for host entries"
17
- @app.call(env)
18
17
  addHostEntries()
18
+ @app.call(env)
19
19
  end
20
20
 
21
21
  end
@@ -7,8 +7,11 @@ module VagrantPlugins
7
7
  ips = []
8
8
  @machine.config.vm.networks.each do |network|
9
9
  key, options = network[0], network[1]
10
- ip = options[:ip] if key == :private_network
10
+ ip = options[:ip] if (key == :private_network || key == :public_network) && options[:hostsupdater] != "skip"
11
11
  ips.push(ip) if ip
12
+ if options[:hostsupdater] == 'skip'
13
+ @ui.info 'Skipping adding host entries (config.vm.network hostsupdater: "skip" is set)'
14
+ end
12
15
  end
13
16
  return ips
14
17
  end
@@ -74,8 +77,8 @@ module VagrantPlugins
74
77
 
75
78
  def addToHosts(entries)
76
79
  return if entries.length == 0
77
- content = entries.join("\n").strip
78
- if !File.writable?(@@hosts_path)
80
+ content = entries.join("\n").strip.concat("\n")
81
+ if !File.writable_real?(@@hosts_path)
79
82
  sudo(%Q(sh -c 'echo "#{content}" >> #@@hosts_path'))
80
83
  else
81
84
  content = "\n" + content
@@ -88,7 +91,7 @@ module VagrantPlugins
88
91
  def removeFromHosts(options = {})
89
92
  uuid = @machine.id || @machine.config.hostsupdater.id
90
93
  hashedId = Digest::MD5.hexdigest(uuid)
91
- if !File.writable?(@@hosts_path)
94
+ if !File.writable_real?(@@hosts_path)
92
95
  sudo(%Q(sed -i -e '/#{hashedId}/ d' #@@hosts_path))
93
96
  else
94
97
  hosts = ""
@@ -17,7 +17,12 @@ module VagrantPlugins
17
17
  end
18
18
 
19
19
  action_hook(:hostsupdater, :machine_action_up) do |hook|
20
- hook.append(Action::UpdateHosts)
20
+ hook.prepend(Action::RemoveHosts)
21
+ hook.after(Action::RemoveHosts, Action::UpdateHosts)
22
+ end
23
+
24
+ action_hook(:hostsupdater, :machine_action_provision) do |hook|
25
+ hook.before(Vagrant::Action::Builtin::Provision, Action::UpdateHosts)
21
26
  end
22
27
 
23
28
  action_hook(:hostsupdater, :machine_action_halt) do |hook|
@@ -37,10 +42,12 @@ module VagrantPlugins
37
42
  end
38
43
 
39
44
  action_hook(:hostsupdater, :machine_action_reload) do |hook|
45
+ hook.prepend(Action::RemoveHosts)
40
46
  hook.append(Action::UpdateHosts)
41
47
  end
42
48
 
43
49
  action_hook(:hostsupdater, :machine_action_resume) do |hook|
50
+ hook.prepend(Action::RemoveHosts)
44
51
  hook.append(Action::UpdateHosts)
45
52
  end
46
53
 
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module HostsUpdater
3
- VERSION = "0.0.11"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -4,20 +4,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'vagrant-hostsupdater/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "vagrant-hostsupdater"
7
+ spec.name = 'vagrant-hostsupdater'
8
8
  spec.version = VagrantPlugins::HostsUpdater::VERSION
9
- spec.authors = ["Falk Kühnel"]
10
- spec.email = ["fk@cogitatio.de"]
9
+ spec.authors = ['Falk Kühnel', 'Chris Smith']
10
+ spec.email = ['fk@cogitatio.de', 'chris@cgsmith.net']
11
11
  spec.description = %q{Enables Vagrant to update hosts file on the host machine}
12
- spec.summary = %q{Enables Vagrant to update hosts file on the host machine}
13
- spec.homepage = "https://github.com/cogitatio/vagrant-hostsupdater"
14
- spec.license = "MIT"
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/cogitatio/vagrant-hostsupdater'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
23
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-hostsupdater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Falk Kühnel
8
+ - Chris Smith
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-10-31 00:00:00.000000000 Z
12
+ date: 2015-11-08 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -41,6 +42,7 @@ dependencies:
41
42
  description: Enables Vagrant to update hosts file on the host machine
42
43
  email:
43
44
  - fk@cogitatio.de
45
+ - chris@cgsmith.net
44
46
  executables: []
45
47
  extensions: []
46
48
  extra_rdoc_files: []
@@ -80,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
82
  version: '0'
81
83
  requirements: []
82
84
  rubyforge_project:
83
- rubygems_version: 2.0.3
85
+ rubygems_version: 2.0.14
84
86
  signing_key:
85
87
  specification_version: 4
86
88
  summary: Enables Vagrant to update hosts file on the host machine