vagrant-etchosts 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.md +26 -2
- data/Rakefile +2 -0
- data/lib/vagrant-etchosts/action/add_etc_hosts_entry.rb +6 -5
- data/lib/vagrant-etchosts/config.rb +20 -0
- data/lib/vagrant-etchosts/plugin.rb +7 -2
- data/lib/vagrant-etchosts/version.rb +6 -4
- data/vagrant-etchosts.gemspec +3 -2
- metadata +4 -2
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# vagrant-etchosts
|
2
|
-
|
3
1
|
This is a Vagrant 1.4+ (at least, that's all I've tested it on) plugin to
|
4
2
|
add and remove entries from `/etc/hosts` on the machine on which Vagrant is
|
5
3
|
running.
|
@@ -25,3 +23,29 @@ Its limitations are:
|
|
25
23
|
I haven't yet had a need for other addressing schemes, so I haven't added
|
26
24
|
them yet. If you want it, send me a patch or wait until I've found a
|
27
25
|
need for multiple networks and/or statically assigned addresses.
|
26
|
+
|
27
|
+
|
28
|
+
# Usage
|
29
|
+
|
30
|
+
At its most basic, you should just be able to install the plugin:
|
31
|
+
|
32
|
+
vagrant plugin install vagrant-etchosts
|
33
|
+
|
34
|
+
Make sure your Vagrantfile defines hostnames for your machine(s):
|
35
|
+
|
36
|
+
config.vm.hostname = "freddy.example.com"
|
37
|
+
|
38
|
+
And you're away! This configuration will add entries for both the FQDN and
|
39
|
+
shortname (`freddy.example.com` and `freddy`, in the example above) to the
|
40
|
+
host's `/etc/hosts` when the machine is created, and remove them again when
|
41
|
+
the machine is destroyed.
|
42
|
+
|
43
|
+
If you'd like additional aliases for a machine to be added to /etc/hosts,
|
44
|
+
then you'll need to specify them in the config:
|
45
|
+
|
46
|
+
config.etchosts.aliases ["foo", "bar", "baz", "wombat"]
|
47
|
+
|
48
|
+
Aliases won't have a shortname variant added, so if you want to have
|
49
|
+
shortname aliases, you'll have to specify both versions yourself:
|
50
|
+
|
51
|
+
config.etchosts.aliases ["puppet.example.com", "puppet"]
|
data/Rakefile
CHANGED
@@ -12,9 +12,10 @@ module VagrantPlugins::EtcHosts
|
|
12
12
|
@app.call(env)
|
13
13
|
|
14
14
|
# Best place to find the network config? In the SSH config.
|
15
|
-
addr
|
16
|
-
fqdn
|
17
|
-
id
|
15
|
+
addr = env[:machine].ssh_info[:host]
|
16
|
+
fqdn = env[:machine].config.vm.hostname
|
17
|
+
id = env[:machine].id
|
18
|
+
aliases = env[:machine].config.etchosts.aliases
|
18
19
|
|
19
20
|
if fqdn.nil?
|
20
21
|
fqdn = env[:machine].name.to_s
|
@@ -28,8 +29,8 @@ module VagrantPlugins::EtcHosts
|
|
28
29
|
begin
|
29
30
|
# Dump existing /etc/hosts content into our temp file
|
30
31
|
tmp.write(File.read(ETC_HOSTS))
|
31
|
-
tmp << "#{addr} #{fqdn} #{shortname} # VAGRANT ID: #{id}\n"
|
32
|
-
|
32
|
+
tmp << "#{addr} #{fqdn} #{shortname} #{aliases.join(' ')} # VAGRANT ID: #{id}\n"
|
33
|
+
|
33
34
|
tmp.close
|
34
35
|
`sudo cp #{tmp.path} /etc/hosts`
|
35
36
|
`sudo pkill -HUP dnsmasq`
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module EtcHosts
|
5
|
+
class Config < Vagrant.plugin("2", :config)
|
6
|
+
attr_accessor :aliases
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@aliases = UNSET_VALUE
|
10
|
+
end
|
11
|
+
|
12
|
+
def finalize!
|
13
|
+
@aliases = [] if @aliases == UNSET_VALUE
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate(machine)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'vagrant-etchosts/action/add_etc_hosts_entry'
|
2
2
|
require 'vagrant-etchosts/action/remove_etc_hosts_entry'
|
3
|
+
require 'vagrant-etchosts/config'
|
3
4
|
|
4
5
|
module VagrantPlugins::EtcHosts
|
5
6
|
class Plugin < Vagrant.plugin("2")
|
@@ -7,11 +8,15 @@ module VagrantPlugins::EtcHosts
|
|
7
8
|
description <<-DESC.gsub(/^\t\t\t/, '')
|
8
9
|
This plugin manages the /etc/hosts file on the host machine.
|
9
10
|
DESC
|
10
|
-
|
11
|
+
|
12
|
+
config(:etchosts) do
|
13
|
+
VagrantPlugins::EtcHosts::Config
|
14
|
+
end
|
15
|
+
|
11
16
|
action_hook(:etchosts, :machine_action_up) do |hook|
|
12
17
|
hook.after ::Vagrant::Action::Builtin::SetHostname, ::VagrantPlugins::EtcHosts::AddEtcHostsEntry
|
13
18
|
end
|
14
|
-
|
19
|
+
|
15
20
|
action_hook(:etchosts, :machine_action_destroy) do |hook|
|
16
21
|
hook.prepend VagrantPlugins::EtcHosts::RemoveEtcHostsEntry
|
17
22
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
require 'git-version-bump'
|
2
|
+
|
1
3
|
module VagrantPlugins
|
2
4
|
module EtcHosts
|
3
|
-
VERSION_MAJOR =
|
4
|
-
VERSION_MINOR =
|
5
|
-
VERSION_PATCH =
|
5
|
+
VERSION_MAJOR = GVB.major_version
|
6
|
+
VERSION_MINOR = GVB.minor_version
|
7
|
+
VERSION_PATCH = GVB.patch_version
|
6
8
|
|
7
|
-
VERSION =
|
9
|
+
VERSION = GVB.version
|
8
10
|
end
|
9
11
|
end
|
data/vagrant-etchosts.gemspec
CHANGED
@@ -3,11 +3,12 @@
|
|
3
3
|
lib = File.expand_path('../lib', __FILE__)
|
4
4
|
$: << File.expand_path('../lib', __FILE__)
|
5
5
|
|
6
|
-
require '
|
6
|
+
require 'git-version-bump'
|
7
7
|
|
8
8
|
Gem::Specification.new do |gem|
|
9
9
|
gem.name = 'vagrant-etchosts'
|
10
|
-
gem.version =
|
10
|
+
gem.version = GVB.version
|
11
|
+
gem.date = GVB.date
|
11
12
|
gem.authors = ['Matt Palmer']
|
12
13
|
gem.email = ['theshed+vagrant-etchosts@hezmatt.org']
|
13
14
|
gem.description = %q{A Vagrant plugin that manages the /etc/hosts file on the host}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-etchosts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -51,11 +51,13 @@ extensions: []
|
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
53
|
- .gitignore
|
54
|
+
- Gemfile
|
54
55
|
- README.md
|
55
56
|
- Rakefile
|
56
57
|
- lib/vagrant-etchosts.rb
|
57
58
|
- lib/vagrant-etchosts/action/add_etc_hosts_entry.rb
|
58
59
|
- lib/vagrant-etchosts/action/remove_etc_hosts_entry.rb
|
60
|
+
- lib/vagrant-etchosts/config.rb
|
59
61
|
- lib/vagrant-etchosts/plugin.rb
|
60
62
|
- lib/vagrant-etchosts/version.rb
|
61
63
|
- vagrant-etchosts.gemspec
|