vagrant-hosts 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 802263ab44d128add4e915e7a5ebaf01a67c547c
4
- data.tar.gz: ab286d7e0b2d74f1b951169ae255cc5922ab1cbc
3
+ metadata.gz: 5e280c9aab6f0c95b6d900daa557e0204d5fb139
4
+ data.tar.gz: cfed85229e73ccf44feba8e0dab64832f542373f
5
5
  SHA512:
6
- metadata.gz: 5cafc5418e59b07c379d1f227651c42bbac05418cdbbb4bf909ca853b7b87ac6f17f5630b99039f0a76e7b550cfebc81ef71ffad69645128657275e89014fe5a
7
- data.tar.gz: 5c47aa690303b42436d1bf432e0f2060ed09ae53a3562e305881c44655446c7ce827233388ca19b13ae4092e5623464ef961788cfbfda642b280a2e7f07d5df8
6
+ metadata.gz: 588ee4e96c2eef297928753d15694fc3fa3abb2477c91a53431d16332102e3fb729352b703dcf833c1a67452777a42c9529a84a92e7452f782a4210c823047ca
7
+ data.tar.gz: dc5626e84d6ae921e60dd66f3b005fa5243d406c41642142750903c698279310eb59b0322f29cf8a224b09666e974ae384d335babf02cbdc66a56b77e2a290d1
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle
2
+ .ruby-version
3
+ .yardoc
4
+ /doc
5
+ Gemfile.lock
6
+ Gemfile.local
7
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ ---
2
+ language: ruby
3
+ sudo: false
4
+ before_install:
5
+ - gem install bundler --version $BUNDLER_VERSION
6
+ install: bundle _${BUNDLER_VERSION}_ install --without development
7
+ script: bundle _${BUNDLER_VERSION}_ exec rspec --color --format documentation
8
+ notifications:
9
+ email: false
10
+ rvm:
11
+ - 2.0.0
12
+ env:
13
+ global:
14
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
15
+ matrix:
16
+ - TEST_VAGRANT_VERSION=v1.6.5 BUNDLER_VERSION=1.6.9
17
+ - TEST_VAGRANT_VERSION=v1.7.4 BUNDLER_VERSION=1.10.5
18
+ - TEST_VAGRANT_VERSION=HEAD BUNDLER_VERSION=1.10.5
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/CHANGELOG CHANGED
@@ -1,6 +1,19 @@
1
1
  CHANGELOG
2
2
  =========
3
3
 
4
+ 2.6.0
5
+ -----
6
+
7
+ 2015-11-08
8
+
9
+ This is a backwards compatible feature release.
10
+
11
+ * (GH-17) Added a new `sync_hosts` option which triggers an update of all
12
+ hosts whenever one host is changed. This also occurs on VM destruction.
13
+
14
+ * Updated README with much missing documentation.
15
+
16
+
4
17
  2.5.0
5
18
  -----
6
19
 
data/Gemfile ADDED
@@ -0,0 +1,28 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.0.0' # Required by Vagrant 1.4 and newer.
3
+
4
+ ENV['TEST_VAGRANT_VERSION'] ||= 'v1.7.4'
5
+
6
+ # Wrapping gemspec in the :plugins group causes Vagrant 1.5 and newer to
7
+ # automagically load this plugin during acceptance tests.
8
+ group :plugins do
9
+ gemspec
10
+ end
11
+
12
+ group :development do
13
+ gem 'yard', '~> 0.8.7'
14
+ gem 'redcarpet'
15
+ end
16
+
17
+ group :test do
18
+ if ENV['TEST_VAGRANT_VERSION'] == 'HEAD'
19
+ gem 'vagrant', :github => 'mitchellh/vagrant', :branch => 'master'
20
+ else
21
+ gem 'vagrant', :github => 'mitchellh/vagrant', :tag => ENV['TEST_VAGRANT_VERSION']
22
+ end
23
+
24
+ # Pinned on 12/10/2014. Compatible with Vagrant 1.5.x, 1.6.x and 1.7.x.
25
+ gem 'vagrant-spec', :github => 'mitchellh/vagrant-spec', :ref => '1df5a3a'
26
+ end
27
+
28
+ eval_gemfile "#{__FILE__}.local" if File.exists? "#{__FILE__}.local"
data/README.markdown CHANGED
@@ -3,14 +3,45 @@ vagrant-hosts
3
3
 
4
4
  Manage vagrant guest local DNS resolution.
5
5
 
6
+ [![Build Status](https://travis-ci.org/oscar-stack/vagrant-hosts.svg?branch=master)](https://travis-ci.org/oscar-stack/vagrant-hosts)
7
+
6
8
  Synopsis
7
- --------
9
+ ========
10
+
11
+ The `vagrant-hosts` plugin provides a `hosts` provisioner which assembles hosts file content based on explicit information and `private_network` settings. Dynamic sources of hostname info, such as DHCP or provider-specific SSH info are currently not considered.
12
+
13
+
14
+ Provisioner Settings
15
+ --------------------
16
+
17
+ These settings are on a per provisioner basis. They configure the individual
18
+ behaviors of each provisioner instance.
19
+
20
+ * `hosts`
21
+ * Description: An array of tuples containing:
22
+ - An IP address
23
+ - A list of hostnames match with that address.
24
+ * Default: `[]`
25
+ * `autoconfigure`
26
+ * Description: A boolean which controls whether hosts are pulled in from other machines.
27
+ * Default: `true` if hosts is empty, otherwise `false`.
28
+ * `add_localhost_hostnames`
29
+ * Description: A boolean which controls whether the hostname of the machine is added as an alias for `127.0.1.1`
30
+ * Default: `true`
31
+ * `sync_hosts`
32
+ * Description: A boolean which controls whether running the hosts provisioner causes an update on all other running machines.
33
+ This also happens during machine destruction.
34
+ * Default: `false`
35
+
36
+
37
+ Example Usage
38
+ -------------
8
39
 
9
40
  Manually specify addresses:
10
41
 
11
42
  ```ruby
12
43
  Vagrant.configure('2') do |config|
13
- config.vm.box = "ubuntu-12.04-server-i386"
44
+ config.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
14
45
 
15
46
  config.vm.provision :hosts do |provisioner|
16
47
  # Add a single hostname
@@ -41,15 +72,15 @@ Autodetect internal network addresses and autoconfigure hosts:
41
72
  Vagrant.configure('2') do |config|
42
73
 
43
74
  config.vm.define :first do |node|
44
- node.vm.box = "ubuntu-12.04-server-i386"
75
+ node.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
45
76
  node.vm.network :private_network, :ip => '10.20.1.2'
46
- node.vm.provision :hosts
77
+ node.vm.provision :hosts, :sync_hosts => true
47
78
  end
48
79
 
49
80
  config.vm.define :second do |node|
50
- node.vm.box = "ubuntu-12.04-server-i386"
81
+ node.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
51
82
  node.vm.network :private_network, :ip => '10.20.1.3'
52
- node.vm.provision :hosts
83
+ node.vm.provision :hosts, :sync_hosts => true
53
84
  end
54
85
  end
55
86
  ```
@@ -62,26 +93,36 @@ Use autodetection with manual entries
62
93
  Vagrant.configure('2') do |config|
63
94
 
64
95
  config.vm.define :first do |node|
65
- node.vm.box = "ubuntu-12.04-server-i386"
96
+ node.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
66
97
  node.vm.network :private_network, :ip => '10.20.1.2'
67
98
  node.vm.provision :hosts do |provisioner|
68
99
  provisioner.autoconfigure = true
100
+ provisioner.sync_hosts = true
69
101
  provisioner.add_host '172.16.3.10', ['yum.mirror.local']
70
102
  end
71
103
 
72
104
  end
73
105
 
74
106
  config.vm.define :second do |node|
75
- node.vm.box = "ubuntu-12.04-server-i386"
107
+ node.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
76
108
  node.vm.network :private_network, :ip => '10.20.1.3'
77
109
  node.vm.provision :hosts do |provisioner|
78
110
  provisioner.autoconfigure = true
111
+ provisioner.sync_hosts = true
79
112
  provisioner.add_host '172.16.3.11', ['apt.mirror.local']
80
113
  end
81
114
  end
82
115
  end
83
116
  ```
84
117
 
118
+ Vagrant Commands
119
+ ----------------
120
+
121
+ The `vagrant-hosts` plugin provides two Vagrant commands:
122
+
123
+ - `vagrant hosts list`: List private_network host info in /etc/hosts format
124
+ - `vagrant hosts puppetize`: List private_network host info as Puppet Host resources
125
+
85
126
  Supported Platforms
86
127
  -------------------
87
128
 
@@ -89,7 +130,8 @@ As of version 1.0.0 or later Vagrant 1.1 is required.
89
130
 
90
131
  Supported guests:
91
132
 
92
- * Linux
133
+ * POSIX
134
+ * Windows
93
135
 
94
136
  Installation
95
137
  ------------
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ task_dir = File.expand_path('../tasks', __FILE__)
2
+
3
+ Dir["#{task_dir}/**/*.rake"].each do |task_file|
4
+ load task_file
5
+ end
@@ -11,6 +11,10 @@ module VagrantHosts
11
11
  require 'vagrant-hosts/command/puppetize'
12
12
  require 'vagrant-hosts/command/list'
13
13
 
14
+ def self.synopsis
15
+ 'Information about hostnames managed by the vagrant-hosts plugin'
16
+ end
17
+
14
18
  def initialize(argv, env)
15
19
  @argv = argv
16
20
  @env = env
@@ -3,6 +3,10 @@ class VagrantHosts::Command::List < Vagrant.plugin('2', :command)
3
3
  include VagrantHosts::Command::Helpers
4
4
  include VagrantHosts::Addresses
5
5
 
6
+ def self.synopsis
7
+ 'List private_network host info in /etc/hosts format'
8
+ end
9
+
6
10
  def initialize(argv, env)
7
11
  @argv = argv
8
12
  @env = env
@@ -3,6 +3,10 @@ class VagrantHosts::Command::Puppetize < Vagrant.plugin('2', :command)
3
3
  include VagrantHosts::Command::Helpers
4
4
  include VagrantHosts::Addresses
5
5
 
6
+ def self.synopsis
7
+ 'List private_network host info as Puppet Host resources'
8
+ end
9
+
6
10
  def initialize(argv, env)
7
11
  @argv = argv
8
12
  @env = env
@@ -12,16 +12,24 @@ module VagrantHosts
12
12
  # other vagrant machines
13
13
  attr_accessor :autoconfigure
14
14
 
15
- # @!attribute autoconfigure
15
+ # @!attribute add_localhost_hostnames
16
16
  # @return [TrueClass, FalseClass] A boolean indicating whether a
17
17
  # `127.0.1.1` entry should be added mapping to the FQDN of the VM.
18
18
  # Default: `true`.
19
19
  attr_accessor :add_localhost_hostnames
20
20
 
21
+ # @!attribute sync_hosts
22
+ # @return [TrueClass, FalseClass] When set to true, running the hosts
23
+ # provisioner on this VM will update all other running machines that
24
+ # use the hosts provisioner. This action will also occur on machine
25
+ # destruction. Defaults to `false`.
26
+ attr_accessor :sync_hosts
27
+
21
28
  def initialize
22
29
  @hosts = []
23
30
  @autoconfigure = UNSET_VALUE
24
31
  @add_localhost_hostnames = UNSET_VALUE
32
+ @sync_hosts = UNSET_VALUE
25
33
  end
26
34
 
27
35
  # Register a host for entry
@@ -53,14 +61,17 @@ module VagrantHosts
53
61
  if @add_localhost_hostnames == UNSET_VALUE
54
62
  @add_localhost_hostnames = true
55
63
  end
64
+
65
+ @sync_hosts = false if @sync_hosts == UNSET_VALUE
56
66
  end
57
67
 
58
68
  # @param other [VagrantHosts::Config]
59
69
  # @return [VagrantHosts::Config] The merged results
60
70
  def merge(other)
61
- super.tap do |result|
62
- result.hosts += other.hosts
63
- end
71
+ result = super
72
+ result.instance_variable_set(:@hosts, self.hosts.dup + other.hosts.dup)
73
+
74
+ result
64
75
  end
65
76
 
66
77
  def validate(machine)
@@ -10,6 +10,8 @@ module VagrantHosts
10
10
  attr_accessor :autoconfigure
11
11
  # @!attribute [rw] add_localhost_hostnames
12
12
  attr_accessor :add_localhost_hostnames
13
+ # @!attribute [rw] sync_hosts
14
+ attr_accessor :sync_hosts
13
15
 
14
16
  def initialize
15
17
  @hosts = []
@@ -20,6 +22,7 @@ module VagrantHosts
20
22
  vm_config.provision :hosts do |h_config|
21
23
  h_config.autoconfigure = attr(:autoconfigure) unless attr(:autoconfigure).nil?
22
24
  h_config.add_localhost_hostnames = attr(:add_localhost_hostnames) unless attr(:add_localhost_hostnames).nil?
25
+ h_config.sync_hosts = attr(:sync_hosts) unless attr(:sync_hosts).nil?
23
26
 
24
27
  @hosts.each do |(address, aliases)|
25
28
  h_config.add_host address, aliases
@@ -4,12 +4,51 @@ module VagrantHosts
4
4
  module Provisioner
5
5
  class Hosts < Vagrant.plugin('2', :provisioner)
6
6
 
7
- def initialize(machine, config)
8
- super
9
- end
10
-
11
7
  def provision
12
8
  @machine.guest.capability(:sync_hosts, @config)
9
+ sync_hosts! if @config.sync_hosts
10
+ end
11
+
12
+ def cleanup
13
+ sync_hosts! if @config.sync_hosts
14
+ end
15
+
16
+ private
17
+
18
+ # Update hosts on other VMs.
19
+ def sync_hosts!
20
+ env = @machine.env
21
+
22
+ # Gathers every _other_ machine in the vagrant environment which is
23
+ # running and has a hosts provider.
24
+ machines_to_provision = env.active_machines.map do |name, provider|
25
+ env.machine(name, provider)
26
+ end.select do |vm|
27
+ calling_machine = (vm.name.to_s == machine.name.to_s)
28
+ running = begin
29
+ vm.communicate.ready?
30
+ rescue Vagrant::Errors::VagrantError
31
+ # WinRM will raise an error if the VM isn't running instead of
32
+ # returning false (mitchellh/vagrant#6356).
33
+ false
34
+ end
35
+ has_hosts = vm.config.provisioners.any? {|p| p.type.intern == :hosts}
36
+
37
+ running && has_hosts && (not calling_machine)
38
+ end
39
+
40
+ machines_to_provision.each do |vm|
41
+ vm.ui.info "Updating hosts on: #{vm.name}"
42
+ vm.config.vm.provisioners.select {|p| p.type.intern == :hosts}.each do |p|
43
+ # Duplicate the hosts configuration.
44
+ hosts_config = @config.class.new.merge(p.config)
45
+ # Set sync_hosts to false to avoid recursion.
46
+ hosts_config.sync_hosts = false
47
+ hosts_config.finalize!
48
+
49
+ self.class.new(vm, hosts_config).provision
50
+ end
51
+ end
13
52
  end
14
53
 
15
54
  end
@@ -1,3 +1,3 @@
1
1
  module VagrantHosts
2
- VERSION = '2.5.0'
2
+ VERSION = '2.6.0'
3
3
  end
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ # Disable Vagrant autoloading so that other plugins defined in the Gemfile for
4
+ # Acceptance tests are not loaded.
5
+ ENV['VAGRANT_NO_PLUGINS'] = '1'
6
+
7
+ require 'vagrant-spec/unit'
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ require 'vagrant-hosts/config'
4
+
5
+ describe VagrantHosts::Config do
6
+ let(:machine) { double('machine') }
7
+
8
+ describe 'hosts' do
9
+ it 'requires aliases to be an array' do
10
+ subject.add_host '127.0.0.1', 'local.server'
11
+ subject.finalize!
12
+
13
+ errors = subject.validate(machine)
14
+
15
+ expect(errors['Vagrant Hosts'].to_s).to match(/should have an array of aliases/)
16
+ end
17
+
18
+ it 'accepts an array of aliases' do
19
+ subject.add_host '127.0.0.1', ['local.server']
20
+ subject.finalize!
21
+
22
+ errors = subject.validate(machine)
23
+
24
+ expect(errors['Vagrant Hosts']).to eq []
25
+ end
26
+
27
+ it 'can be merged' do
28
+ subject.add_host '127.0.0.1', ['local.server']
29
+ subject.finalize!
30
+
31
+ other = described_class.new
32
+ other.add_host '10.0.20.1', ['other.server']
33
+ other.finalize!
34
+
35
+ result = subject.merge(other)
36
+
37
+ expect(result.hosts).to eq [
38
+ ["127.0.0.1", ["local.server"]],
39
+ ["10.0.20.1", ["other.server"]]]
40
+ end
41
+
42
+ end
43
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,3 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
@@ -21,4 +21,8 @@ Gem::Specification.new do |gem|
21
21
 
22
22
  gem.files = %x{git ls-files -z}.split("\0")
23
23
  gem.require_path = 'lib'
24
+
25
+ gem.add_development_dependency 'rake'
26
+ # Pin to 2.14.x for compatibility with vagrant-spec.
27
+ gem.add_development_dependency 'rspec', '~> 2.14.0'
24
28
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-hosts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Thebo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-16 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.14.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.14.0
13
41
  description: |2
14
42
  Manage static DNS entries and configuration for Vagrant guests.
15
43
  email: adrien@somethingsinistral.net
@@ -17,9 +45,15 @@ executables: []
17
45
  extensions: []
18
46
  extra_rdoc_files: []
19
47
  files:
48
+ - .gitignore
49
+ - .rspec
50
+ - .travis.yml
51
+ - .yardopts
20
52
  - CHANGELOG
53
+ - Gemfile
21
54
  - LICENSE
22
55
  - README.markdown
56
+ - Rakefile
23
57
  - lib/vagrant-hosts.rb
24
58
  - lib/vagrant-hosts/addresses.rb
25
59
  - lib/vagrant-hosts/cap.rb
@@ -35,6 +69,9 @@ files:
35
69
  - lib/vagrant-hosts/plugin.rb
36
70
  - lib/vagrant-hosts/provisioner/hosts.rb
37
71
  - lib/vagrant-hosts/version.rb
72
+ - spec/spec_helper.rb
73
+ - spec/unit/config_spec.rb
74
+ - tasks/spec.rake
38
75
  - templates/locales/en.yml
39
76
  - vagrant-hosts.gemspec
40
77
  homepage: https://github.com/adrienthebo/vagrant-hosts
@@ -47,19 +84,18 @@ require_paths:
47
84
  - lib
48
85
  required_ruby_version: !ruby/object:Gem::Requirement
49
86
  requirements:
50
- - - ">="
87
+ - - '>='
51
88
  - !ruby/object:Gem::Version
52
89
  version: '0'
53
90
  required_rubygems_version: !ruby/object:Gem::Requirement
54
91
  requirements:
55
- - - ">="
92
+ - - '>='
56
93
  - !ruby/object:Gem::Version
57
94
  version: '0'
58
95
  requirements: []
59
96
  rubyforge_project:
60
- rubygems_version: 2.4.3
97
+ rubygems_version: 2.0.14
61
98
  signing_key:
62
99
  specification_version: 4
63
100
  summary: Manage static DNS on vagrant guests
64
101
  test_files: []
65
- has_rdoc: true