vagrant-hostmanager-lite 0.4.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MmIzNmNlYjYzYjA4ZDFjNGIxZDFhNjc1NTM0MmVkYjVlNjM5ZjE1Zg==
5
+ data.tar.gz: !binary |-
6
+ MGNjZjNjYzIxZWU4OGQ3YjA2OGQ2NDI1ZWRmNWI0NmU5YmVlNDg2NA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Yjc4MzYyNjNmN2I2Njc3YmE0ODI1YzA0MWZlMDgyZWY1NDk1YTg5Y2I2Mjhi
10
+ ZWNiMzNhOTA1NTFlYTMyNWE0MWRhMTI2NDRhMmZlNTQ4OTE1MzU2OGJkN2Uz
11
+ NzFjZmJlYmMyODFhNWZlOTZmODcyZDE3ODI4YjE3ZWQ5NzM3ZDg=
12
+ data.tar.gz: !binary |-
13
+ OTk0OGNlYmRlY2Y4OWNmMjI2NGE4ZGRlZTNiZjA4MGE1NjZmMmM0NmExMDIz
14
+ MGExZDNmNjVmNDVhYTE2YmJhNzE3OTQ5ODc1YzBjMDM0Njg2YjZjN2IyN2E0
15
+ Zjg2YzhkZTUyN2I0ZjA3NmQxMTljMTUwZGI5YzdjMzVmMWVhYjU=
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ pkg
3
+ Gemfile.lock
4
+ test/.vagrant
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ sudo: false
2
+ rvm:
3
+ - 2.0.0
4
+
5
+ script:
6
+ - true # Integration tests cannot run on Travis... http://omerkatz.com/blog/2013/6/15/travis-ci-does-not-work-when-you-package-vagrant-boxes-as-a-build-step-yet
7
+
8
+ deploy:
9
+ provider: rubygems
10
+ api_key:
11
+ secure: Q0yUnJypPr23nkoDhp3gfHzyvUYWOqdWWZJ+dqStDuU5TMVb+RTCAtx8m+K6pDcQRdHcqQYsdbGO7mbEGmSMkhGpzMNyRj7hyPID81JU3+NgMdjFmmfU7DijcdTwmNyAM/IoKfgc7qrCZ2ESZR+wVNXubM/lIIREddMcAD7X1zo=
12
+ gem: vagrant-hostmanager-lite
13
+ on:
14
+ tags: true
15
+ repo: mat128/vagrant-hostmanager
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.2.1'
4
+ gem 'rake'
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Shawn Dahlen
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,84 @@
1
+ Vagrant Host Manager
2
+ ====================
3
+ `vagrant-hostmanager` is a Vagrant 1.1+ plugin that manages the `/etc/hosts`
4
+ file on guest machines. Its goal is to enable resolution of multi-machine
5
+ environments deployed with a cloud provider where IP addresses are not known
6
+ in advance.
7
+
8
+ Status
9
+ ------
10
+ The current implementation is a proof-of-concept supporting the larger
11
+ objective of using Vagrant as a cloud management interface for development
12
+ and production environments.
13
+
14
+ The plugin has been tested with Vagrant 1.1.5.
15
+
16
+ Installation
17
+ ------------
18
+ Install the plugin following the typical Vagrant 1.1 procedure:
19
+
20
+ $ vagrant plugin install vagrant-hostmanager-lite
21
+
22
+ Usage
23
+ -----
24
+ To update the `/etc/hosts` file on each active machine, run the following
25
+ command:
26
+
27
+ $ vagrant hostmanager
28
+
29
+ The plugin may hook into the `vagrant up` and `vagrant destroy` commands
30
+ automatically. When a machine is created or destroyed, all active
31
+ machines with the same provider will have their `/etc/hosts` file updated
32
+ accordingly. Set the `hostmanager.enabled` attribute to `true` in the
33
+ Vagrantfile to activate this behavior.
34
+
35
+ A machine's IP address is defined by either the static IP for a private
36
+ network configuration or by the SSH host configuration. To disable
37
+ using the private network IP address, set `config.hostmanger.ignore_private_ip`
38
+ to true.
39
+
40
+ A machine's host name is defined by `config.vm.hostname`. If this is not
41
+ set, it falls back to the symbol defining the machine in the Vagrantfile.
42
+
43
+ When using include_offline set to true, only boxes that are up or have a
44
+ private ip configured will be added to the hosts file. You will receive a
45
+ warning on skipped boxes.
46
+
47
+ In addition, the `hostmanager.aliases` configuration attribute can be used
48
+ to provide aliases for your host names.
49
+
50
+ Example configuration:
51
+
52
+ ```ruby
53
+ Vagrant.configure("2") do |config|
54
+ config.hostmanager.enabled = true
55
+ config.hostmanager.ignore_private_ip = false
56
+ config.hostmanager.include_offline = true
57
+ config.vm.define "example-box" do |node|
58
+ node.vm.hostname = "example-box-hostname"
59
+ node.vm.network :private_network, ip: "192.168.42.42"
60
+ node.hostmanager.aliases = %w(example-box.localdomain example-box-alias)
61
+ end
62
+ end
63
+ ```
64
+
65
+ As a last option, you can also choose hostmanager as a provisioner.
66
+ This allows you to use the provisioning order to ensure that hostmanager
67
+ runs before or after provisioning. The provisioner will collect hosts from
68
+ boxes with the same provider as the running box.
69
+
70
+ Use:
71
+
72
+ ```ruby
73
+ config.vm.provision :hostmanager
74
+ ```
75
+
76
+ Contribute
77
+ ----------
78
+ Contributions are welcome.
79
+
80
+ 1. Fork it
81
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
82
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
83
+ 4. Push to the branch (`git push origin my-new-feature`)
84
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_helper'
2
+
3
+ # Change to the directory of this file.
4
+ Dir.chdir(File.expand_path("../", __FILE__))
5
+
6
+ namespace :gem do
7
+ Bundler::GemHelper.install_tasks
8
+ end
9
+
10
+ task :test do
11
+ sh 'test/test.sh'
12
+ sh 'test/test_plugin_does_not_break_vagrant.sh'
13
+ end
14
+
15
+ task :default => "test"
@@ -0,0 +1,33 @@
1
+ require 'vagrant-hostmanager/hosts_file'
2
+
3
+ module VagrantPlugins
4
+ module HostManager
5
+ module Action
6
+ class UpdateHostsFile
7
+ include HostsFile
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @machine = env[:machine]
12
+ @logger = Log4r::Logger.new('vagrant::hostmanager::update_hosts_file')
13
+ end
14
+
15
+ def call(env)
16
+ # check if machine is already active
17
+ return @app.call(env) if @machine.id
18
+
19
+ # check config to see if the hosts file should be update automatically
20
+ return @app.call(env) unless @machine.config.hostmanager.enabled?
21
+ @logger.info 'Updating /etc/hosts file automatically'
22
+
23
+ # continue the action stack so the machine will be created
24
+ @app.call(env)
25
+
26
+ # update /etc/hosts file on each active machine
27
+ machines = generate(@machine.env, @machine.provider_name)
28
+ machines.each { |machine| update(machine) }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ module VagrantPlugins
2
+ module HostManager
3
+ class Command < Vagrant.plugin('2', :command)
4
+ include HostsFile
5
+
6
+ def execute
7
+ options = {}
8
+ opts = OptionParser.new do |o|
9
+ o.banner = 'Usage: vagrant hostmanager [vm-name]'
10
+ o.separator ''
11
+ o.version = VagrantPlugins::HostManager::VERSION
12
+ o.program_name = 'vagrant hostmanager'
13
+
14
+ o.on('--provider provider', String,
15
+ 'Update machines with the specific provider.') do |provider|
16
+ options[:provider] = provider
17
+ end
18
+ end
19
+
20
+ argv = parse_options(opts)
21
+ return if !argv
22
+
23
+ options[:provider] ||= @env.default_provider
24
+
25
+ generate(@env, options[:provider].to_sym)
26
+
27
+ if argv.length == 0
28
+ @env.active_machines.each do |active_name, active_provider|
29
+ puts active_name
30
+ machine = @env.machine(active_name, active_provider)
31
+ update(machine)
32
+ end
33
+ else
34
+ with_target_vms(argv, options) do |machine|
35
+ update(machine)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,68 @@
1
+ module VagrantPlugins
2
+ module HostManager
3
+ class Config < Vagrant.plugin('2', :config)
4
+ attr_accessor :enabled
5
+ attr_accessor :ignore_private_ip
6
+ attr_accessor :aliases
7
+ attr_accessor :include_offline
8
+
9
+ alias_method :enabled?, :enabled
10
+ alias_method :include_offline?, :include_offline
11
+
12
+ ACCEPTED_CONFIGS = [UNSET_VALUE, true, false]
13
+ INVALID_CONFIG_MESSAGE = "A value for %s must be true, false or unset."
14
+
15
+ def initialize
16
+ @enabled = false
17
+ @ignore_private_ip = UNSET_VALUE
18
+ @aliases = Array.new
19
+ @include_offline = false
20
+ end
21
+
22
+ def finalize!
23
+ @ignore_private_ip = false if @ignore_private_ip == UNSET_VALUE
24
+ @aliases = [ @aliases ].flatten
25
+ end
26
+
27
+ def validate(machine)
28
+ errors = Array.new
29
+
30
+ # check if enabled option is either true or false
31
+ errors << validate_bool('hostmanager.enabled', enabled)
32
+
33
+ # check if include_offline is either true or false
34
+ errors << validate_bool('hostmanager.include_offline', include_offline)
35
+
36
+ # check if ignore_private_ip option is either true or false (or UNSET_VALUE)
37
+ if @ignore_private_ip != UNSET_VALUE
38
+ errors << validate_bool('hostmanager.ignore_private_ip', ignore_private_ip)
39
+ end
40
+
41
+ # check if aliases option is an Array
42
+ if !machine.config.hostmanager.aliases.kind_of?(Array) and
43
+ !machine.config.hostmanager.aliases.kind_of?(String)
44
+ errors << I18n.t('vagrant_hostmanager.config.not_an_array_or_string', {
45
+ :config_key => 'hostmanager.aliases',
46
+ :is_class => aliases.class.to_s,
47
+ })
48
+ end
49
+
50
+ errors.compact!
51
+ { "HostManager configuration" => errors }
52
+ end
53
+
54
+ private
55
+ def validate_bool(key, value)
56
+ if ![TrueClass, FalseClass].include?(value.class)
57
+ I18n.t('vagrant_hostmanager.config.not_a_bool', {
58
+ :config_key => key,
59
+ :value => value.class.to_s,
60
+ })
61
+ else
62
+ nil
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,6 @@
1
+ module VagrantPlugins
2
+ module HostManager
3
+ module Errors
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,94 @@
1
+ require 'vagrant-hostmanager/util'
2
+
3
+ module VagrantPlugins
4
+ module HostManager
5
+ module HostsFile
6
+ # Generate a hosts file containing the the active machines
7
+ # in the Vagrant environment backed by the specified provider.
8
+ # The file is written to the Vagrant temporary path.
9
+ def generate(env, provider)
10
+ machines = []
11
+
12
+ # define a lambda for looking up a machine's ip address
13
+ get_ip_address = lambda do |machine|
14
+ ip = nil
15
+ if machine.config.hostmanager.ignore_private_ip != true
16
+ machine.config.vm.networks.each do |network|
17
+ key, options = network[0], network[1]
18
+ ip = options[:ip] if key == :private_network
19
+ next if ip
20
+ end
21
+ end
22
+ ip || (machine.ssh_info ? machine.ssh_info[:host] : nil)
23
+ end
24
+
25
+ # create the temporary hosts file
26
+ path = env.tmp_path.join('hosts')
27
+ File.open(path, 'w') do |file|
28
+ file << "\n"
29
+
30
+ # add a hosts entry for each active machine matching the provider
31
+ get_machines(env, provider).each do |name, p|
32
+ if provider == p
33
+ machines << machine = env.machine(name, provider)
34
+ host = machine.config.vm.hostname || name
35
+ ip = get_ip_address.call(machine)
36
+ if ip
37
+ host_aliases = machine.config.hostmanager.aliases.join("\s").chomp
38
+ machine.env.ui.info I18n.t('vagrant_hostmanager.action.add_host', {
39
+ :ip => ip,
40
+ :host => host,
41
+ :aliases => host_aliases,
42
+ })
43
+ file << "#{ip}\t#{host}\s#{host_aliases}\n"
44
+ else
45
+ machine.env.ui.warn I18n.t('vagrant_hostmanager.action.host_no_ip', {
46
+ :name => name,
47
+ })
48
+ end
49
+ end
50
+ end
51
+ end
52
+ machines
53
+ end
54
+
55
+ # Copy the temporary hosts file to the specified machine overwritting
56
+ # the existing /etc/hosts file.
57
+ def update(machine)
58
+ path = machine.env.tmp_path.join('hosts')
59
+ if machine.communicate.ready?
60
+ machine.env.ui.info I18n.t('vagrant_hostmanager.action.update', {
61
+ :name => machine.name
62
+ })
63
+ machine.communicate.upload(path, '/tmp/hosts')
64
+ machine.communicate.sudo("[ -f /etc/hosts.orig ] || cp /etc/hosts /etc/hosts.orig")
65
+ machine.communicate.sudo("cat /etc/hosts.orig /tmp/hosts > /etc/hosts")
66
+ end
67
+ end
68
+
69
+ private
70
+ # Either use the active machines, or loop over all available machines and
71
+ # get those with the same provider (aka, ignore boxes that throw MachineNotFound errors).
72
+ #
73
+ # Returns an array with the same structure as env.active_machines:
74
+ # [ [:machine, :virtualbox], [:foo, :virtualbox] ]
75
+ def get_machines(env, provider)
76
+ if Util.get_config(env).hostmanager.include_offline?
77
+ machines = []
78
+ env.machine_names.each do |name|
79
+ begin
80
+ m = env.machine(name, provider)
81
+ machines << [name, provider]
82
+ rescue Vagrant::Errors::MachineNotFound => ex
83
+ # ignore this box.
84
+ end
85
+ end
86
+ machines
87
+ else
88
+ env.active_machines
89
+ end
90
+ end
91
+
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,42 @@
1
+ require 'vagrant-hostmanager/action/update_hosts_file'
2
+
3
+ module VagrantPlugins
4
+ module HostManager
5
+ class Plugin < Vagrant.plugin('2')
6
+ name 'HostManager'
7
+ description <<-DESC
8
+ This plugin manages the /etc/hosts file for guest machines. An entry is
9
+ created for each active machine using the hostname attribute.
10
+
11
+ You can also use the hostmanager provisioner to update the hosts file.
12
+ DESC
13
+
14
+ config(:hostmanager) do
15
+ require_relative 'config'
16
+ Config
17
+ end
18
+
19
+ action_hook(:hostmanager, :machine_action_up) do |hook|
20
+ if VagrantPlugins.const_defined?("OpenStack") && VagrantPlugins::OpenStack.const_defined?("Action")
21
+ hook.before(VagrantPlugins::OpenStack::Action::CreateServer, Action::UpdateHostsFile)
22
+ else
23
+ hook.prepend(Action::UpdateHostsFile)
24
+ end
25
+ end
26
+
27
+ action_hook(:hostmanager, :machine_action_destroy) do |hook|
28
+ hook.append(Action::UpdateHostsFile)
29
+ end
30
+
31
+ provisioner(:hostmanager) do
32
+ require_relative 'provisioner'
33
+ Provisioner
34
+ end
35
+
36
+ command(:hostmanager) do
37
+ require_relative 'command'
38
+ Command
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ module VagrantPlugins
2
+ module HostManager
3
+ class Provisioner < Vagrant.plugin('2', :provisioner)
4
+ include HostsFile
5
+
6
+ def provision
7
+ generate(@machine.env, @machine.box.provider.to_sym)
8
+ update(@machine)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module VagrantPlugins
2
+ module HostManager
3
+ module Util
4
+ def self.get_config(env)
5
+ # config_global has been removed from v1.5
6
+ if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
7
+ env.vagrantfile.config
8
+ else
9
+ env.config_global
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module HostManager
3
+ VERSION = '0.4.1'
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ require 'vagrant-hostmanager/plugin'
2
+ require 'vagrant-hostmanager/version'
3
+ require 'vagrant-hostmanager/errors'
4
+
5
+ module VagrantPlugins
6
+ module HostManager
7
+ def self.source_root
8
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
9
+ end
10
+
11
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
12
+ I18n.reload!
13
+ end
14
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,9 @@
1
+ en:
2
+ vagrant_hostmanager:
3
+ action:
4
+ add_host: "Adding /etc/hosts entry: %{ip} %{host} %{aliases}"
5
+ host_no_ip: "Could not determine ip for machine '%{name}': no private ip configured or machine not up."
6
+ update: "[%{name}] Updating /etc/hosts file"
7
+ config:
8
+ not_a_bool: "A value for %{config_key} can only be true or false, not type '%{value}'"
9
+ not_an_array_or_string: "A value for %{config_key} must be an Array or String, not type '%{is_class}'"
data/test/Vagrantfile ADDED
@@ -0,0 +1,23 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.require_plugin('vagrant-hostmanager')
5
+
6
+ Vagrant.configure('2') do |config|
7
+ config.vm.box = 'precise32'
8
+ config.vm.box_url = 'http://files.vagrantup.com/precise32.box'
9
+
10
+ config.hostmanager.enabled = true
11
+
12
+ config.vm.define :server1 do |server|
13
+ server.vm.hostname = 'fry.example.org'
14
+ server.vm.network :private_network, :ip => '10.0.5.2'
15
+ server.hostmanager.aliases = %w(fry42.example.org fry-old.example.org)
16
+ end
17
+
18
+ config.vm.define :server2 do |server|
19
+ server.vm.hostname = 'bender.example.org'
20
+ server.vm.network :private_network, :ip => '10.0.5.3'
21
+ server.hostmanager.aliases = %w(bender42.example.org bender-old.example.org)
22
+ end
23
+ end
data/test/functions.sh ADDED
@@ -0,0 +1,30 @@
1
+ #!/bin/sh
2
+ # cleanup
3
+ cleanup_file="$(mktemp ${TMPDIR-"/tmp"}/trap_cleanup.XXXXXXXX)"
4
+
5
+ cleanup_trap() {
6
+ set +e
7
+ . ${cleanup_file}
8
+ rm -f ${cleanup_file}
9
+ }
10
+ trap cleanup_trap INT EXIT TERM
11
+
12
+ register_cleanup_function() {
13
+ echo "${@}" >> ${cleanup_file}
14
+ }
15
+ # /cleanup
16
+
17
+ vagrant_ssh() {
18
+ local vm=$1; shift
19
+ local cfg=$(mktemp ${TMPDIR-"/tmp"}/vagrant_ssh.XXXXXXXX)
20
+ register_cleanup_function rm $cfg
21
+
22
+ vagrant ssh-config $vm | grep -A 100 ^Host > $cfg
23
+ ssh -F $cfg vagrant@$vm "${@}"
24
+ }
25
+
26
+ fail() {
27
+ local message=$1
28
+ echo "Failure: $message" 1>&2
29
+ exit 1
30
+ }
@@ -0,0 +1,12 @@
1
+ 127.0.0.1 localhost
2
+ 127.0.1.1 fry.example.org fry precise32
3
+
4
+ # The following lines are desirable for IPv6 capable hosts
5
+ ::1 ip6-localhost ip6-loopback
6
+ fe00::0 ip6-localnet
7
+ ff00::0 ip6-mcastprefix
8
+ ff02::1 ip6-allnodes
9
+ ff02::2 ip6-allrouters
10
+
11
+ 10.0.5.2 fry.example.org fry42.example.org fry-old.example.org
12
+ 10.0.5.3 bender.example.org bender42.example.org bender-old.example.org
@@ -0,0 +1,9 @@
1
+ 127.0.0.1 localhost
2
+ 127.0.1.1 fry.example.org fry precise32
3
+
4
+ # The following lines are desirable for IPv6 capable hosts
5
+ ::1 ip6-localhost ip6-loopback
6
+ fe00::0 ip6-localnet
7
+ ff00::0 ip6-mcastprefix
8
+ ff02::1 ip6-allnodes
9
+ ff02::2 ip6-allrouters
@@ -0,0 +1,12 @@
1
+ 127.0.0.1 localhost
2
+ 127.0.1.1 bender.example.org bender precise32
3
+
4
+ # The following lines are desirable for IPv6 capable hosts
5
+ ::1 ip6-localhost ip6-loopback
6
+ fe00::0 ip6-localnet
7
+ ff00::0 ip6-mcastprefix
8
+ ff02::1 ip6-allnodes
9
+ ff02::2 ip6-allrouters
10
+
11
+ 10.0.5.2 fry.example.org fry42.example.org fry-old.example.org
12
+ 10.0.5.3 bender.example.org bender42.example.org bender-old.example.org
@@ -0,0 +1,11 @@
1
+ 127.0.0.1 localhost
2
+ 127.0.1.1 bender.example.org bender precise32
3
+
4
+ # The following lines are desirable for IPv6 capable hosts
5
+ ::1 ip6-localhost ip6-loopback
6
+ fe00::0 ip6-localnet
7
+ ff00::0 ip6-mcastprefix
8
+ ff02::1 ip6-allnodes
9
+ ff02::2 ip6-allrouters
10
+
11
+ 10.0.5.3 bender.example.org bender42.example.org bender-old.example.org
@@ -0,0 +1,9 @@
1
+ 127.0.0.1 localhost
2
+ 127.0.1.1 bender.example.org bender precise32
3
+
4
+ # The following lines are desirable for IPv6 capable hosts
5
+ ::1 ip6-localhost ip6-loopback
6
+ fe00::0 ip6-localnet
7
+ ff00::0 ip6-mcastprefix
8
+ ff02::1 ip6-allnodes
9
+ ff02::2 ip6-allrouters
data/test/test.sh ADDED
@@ -0,0 +1,38 @@
1
+ #!/bin/bash
2
+ . $(dirname $0)/functions.sh
3
+ cd $(dirname $0)
4
+ set -e
5
+
6
+ register_cleanup_function vagrant destroy -f
7
+ vagrant up
8
+
9
+ servers="server1 server2"
10
+
11
+ for server in ${servers}; do
12
+ echo "[${server}] assert original output is what we expected"
13
+ actual=$(vagrant_ssh ${server} 'cat /etc/hosts' | sort)
14
+ expected=$(cat ${server}.prestine.hosts.file.txt | sort)
15
+ [ "${actual}" == "${expected}" ] || fail "Original hosts file does not match what we expected for server ${server}"
16
+ done
17
+
18
+ vagrant hostmanager
19
+
20
+ for server in ${servers}; do
21
+ echo "[${server}] assert output is what we expect after hostmanager"
22
+ actual=$(vagrant_ssh ${server} 'cat /etc/hosts' | sort)
23
+ expected=$(cat ${server}.expected.hosts.file.txt | sort)
24
+ [ "${actual}" == "${expected}" ] || fail "Hosts file after hostmanager modifications do not match for server ${server}"
25
+ done
26
+
27
+ # Assert running twice should replace custom entries
28
+
29
+ vagrant hostmanager
30
+
31
+ for server in ${servers}; do
32
+ echo "[${server}] assert output is what we expect after hostmanager was applied twice"
33
+ actual=$(vagrant_ssh ${server} 'cat /etc/hosts' | sort)
34
+ expected=$(cat ${server}.expected.hosts.file.txt | sort)
35
+ [ "${actual}" == "${expected}" ] || fail "Hosts file after hostmanager modifications (take 2) do not match for server ${server}"
36
+ done
37
+
38
+ echo "All tests passed."
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ . $(dirname $0)/functions.sh
3
+ set -e
4
+
5
+ vagrant_box_dir="$(mktemp -d ${TMPDIR-"/tmp"}/box_dir.XXXXXXXX)"
6
+
7
+ register_cleanup_function "cd ${vagrant_box_dir} && vagrant destroy -f && cd -"
8
+ register_cleanup_function "rm -rf ${vagrant_box_dir}"
9
+
10
+ cd ${vagrant_box_dir}
11
+ vagrant init precise32 http://files.vagrantup.com/precise32.box
12
+ echo "Vagrant.require_plugin('vagrant-hostmanager')" >> Vagrantfile
13
+ vagrant up
14
+ vagrant ssh -c 'true'
15
+ cd -
16
+
17
+ echo "$(basename $0) passed."
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-hostmanager/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'vagrant-hostmanager-lite'
8
+ gem.version = VagrantPlugins::HostManager::VERSION
9
+ gem.authors = ['Shawn Dahlen']
10
+ gem.email = ['shawn@dahlen.me']
11
+ gem.description = %q{A Vagrant plugin that manages the /etc/hosts file within a multi-machine environment}
12
+ gem.summary = gem.description
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.require_paths = ['lib']
17
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-hostmanager-lite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
+ platform: ruby
6
+ authors:
7
+ - Shawn Dahlen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Vagrant plugin that manages the /etc/hosts file within a multi-machine
14
+ environment
15
+ email:
16
+ - shawn@dahlen.me
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .travis.yml
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - lib/vagrant-hostmanager.rb
28
+ - lib/vagrant-hostmanager/action/update_hosts_file.rb
29
+ - lib/vagrant-hostmanager/command.rb
30
+ - lib/vagrant-hostmanager/config.rb
31
+ - lib/vagrant-hostmanager/errors.rb
32
+ - lib/vagrant-hostmanager/hosts_file.rb
33
+ - lib/vagrant-hostmanager/plugin.rb
34
+ - lib/vagrant-hostmanager/provisioner.rb
35
+ - lib/vagrant-hostmanager/util.rb
36
+ - lib/vagrant-hostmanager/version.rb
37
+ - locales/en.yml
38
+ - test/Vagrantfile
39
+ - test/functions.sh
40
+ - test/server1.expected.hosts.file.txt
41
+ - test/server1.prestine.hosts.file.txt
42
+ - test/server2.expected.hosts.file.txt
43
+ - test/server2.post-server1-down.hosts.file.txt
44
+ - test/server2.prestine.hosts.file.txt
45
+ - test/test.sh
46
+ - test/test_plugin_does_not_break_vagrant.sh
47
+ - vagrant-hostmanager-lite.gemspec
48
+ homepage:
49
+ licenses: []
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.4.5
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: A Vagrant plugin that manages the /etc/hosts file within a multi-machine
71
+ environment
72
+ test_files:
73
+ - test/Vagrantfile
74
+ - test/functions.sh
75
+ - test/server1.expected.hosts.file.txt
76
+ - test/server1.prestine.hosts.file.txt
77
+ - test/server2.expected.hosts.file.txt
78
+ - test/server2.post-server1-down.hosts.file.txt
79
+ - test/server2.prestine.hosts.file.txt
80
+ - test/test.sh
81
+ - test/test_plugin_does_not_break_vagrant.sh