vagrant-hitch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/LICENSE +22 -0
- data/README.mkd +47 -0
- data/Rakefile +3 -0
- data/example/Vagrantfile +1 -0
- data/example/config/nodes.yml +22 -0
- data/example/config/provisioner_chef.yml +6 -0
- data/example/config/provisioner_puppet.yml +9 -0
- data/example/config/provisioner_puppet_server.yml +6 -0
- data/lib/deep_merge.rb +26 -0
- data/lib/vagrant-hitch.rb +126 -0
- data/lib/vagrant_init.rb +4 -0
- data/spec/hitch_spec.rb +14 -0
- data/vagrant-hitch.gemspec +18 -0
- metadata +79 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Aziz Shamim, James Fryman
|
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.mkd
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#VagrantHitch
|
2
|
+
|
3
|
+
This vagrant module adds data driven infrastructure to your vagrant environment.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
If you installed it as a ruby gem. Just add the following line to your Vagrantfile
|
8
|
+
|
9
|
+
```
|
10
|
+
Vagrant::Config.run &VagrantHitch.up!(path_to_config_directory)
|
11
|
+
```
|
12
|
+
|
13
|
+
for example:
|
14
|
+
|
15
|
+
```
|
16
|
+
Vagrant::Config.run &VagrantHitch.up!(File.join(File.dirname(__FILE__),'config'))
|
17
|
+
```
|
18
|
+
|
19
|
+
If not installed as a gem, you'll have to source vagrant-hitch appropriately and add to your Vagrantfile:
|
20
|
+
|
21
|
+
```
|
22
|
+
require 'vagrant-hitch'
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Example files are in the /example directory
|
28
|
+
|
29
|
+
### Directory structure
|
30
|
+
The directory structure assumes:
|
31
|
+
|
32
|
+
```
|
33
|
+
. # Project directory
|
34
|
+
├── manifests
|
35
|
+
│ └── site.pp
|
36
|
+
├── modules
|
37
|
+
│ ├── dist
|
38
|
+
│ └── site
|
39
|
+
└── vagrant
|
40
|
+
├── Vagrantfile # Project vagrantfile
|
41
|
+
└── config # The data driven infrastructure directory
|
42
|
+
├── graph
|
43
|
+
│ ├── test1.vagrant.test
|
44
|
+
│ └── test2.vagrant.test
|
45
|
+
├── nodes.yml
|
46
|
+
└── provisioner_puppet.yml
|
47
|
+
```
|
data/Rakefile
ADDED
data/example/Vagrantfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Vagrant::Config.run &VagrantHitch.up!(File.join(File.dirname(__FILE__),'config'))
|
@@ -0,0 +1,22 @@
|
|
1
|
+
default: &default
|
2
|
+
vbox: vbox-name
|
3
|
+
orgname: vagrant.test
|
4
|
+
puppet:
|
5
|
+
manifest_file: site.pp
|
6
|
+
ports:
|
7
|
+
http:
|
8
|
+
host: 10080
|
9
|
+
guest: 80
|
10
|
+
https:
|
11
|
+
host: 10443
|
12
|
+
guest: 443
|
13
|
+
mysql:
|
14
|
+
host: 13310
|
15
|
+
guest: 3306
|
16
|
+
tomcat:
|
17
|
+
host: 18080
|
18
|
+
guest: 8080
|
19
|
+
test1:
|
20
|
+
<<: *default
|
21
|
+
test2:
|
22
|
+
<<: *default
|
data/lib/deep_merge.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#MONKEYPATCHTHATHASH!
|
2
|
+
class ::Hash
|
3
|
+
def deep_merge(hash)
|
4
|
+
|
5
|
+
end
|
6
|
+
|
7
|
+
def deep_merge!(second)
|
8
|
+
deep_safe_merge(self,second)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def deep_safe_merge(source_hash, new_hash)
|
13
|
+
source_hash.merge!(new_hash) do |key, old, new|
|
14
|
+
if new.respond_to?(:blank) && new.blank?
|
15
|
+
old
|
16
|
+
elsif (old.kind_of?(Hash) and new.kind_of?(Hash))
|
17
|
+
deep_safe_merge(old, new)
|
18
|
+
elsif (old.kind_of?(Array) and new.kind_of?(Array))
|
19
|
+
old.concat(new).uniq
|
20
|
+
else
|
21
|
+
new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'vagrant'
|
3
|
+
require File.join(File.dirname(__FILE__),'deep_merge')
|
4
|
+
|
5
|
+
module VagrantHitch
|
6
|
+
def self.validate(cfdir)
|
7
|
+
unless Dir.exist?(cfdir)
|
8
|
+
puts "The directory #{cfdir} is not valid"
|
9
|
+
exit
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.up!(cfdir)
|
14
|
+
self.validate(cfdir)
|
15
|
+
|
16
|
+
return lambda do |config_dir, config|
|
17
|
+
#Load up Config Files
|
18
|
+
begin
|
19
|
+
profiles = YAML::load_file(File.join(config_dir,'nodes.yml'))
|
20
|
+
|
21
|
+
['chef', 'puppet', 'puppet_server'].each do |type|
|
22
|
+
if File.exists?(File.join(config_dir, "provisioner_#{type}.yml"))
|
23
|
+
provisioner_data = YAML::load_file(File.join(config_dir, "provisioner_#{type}.yml"))
|
24
|
+
instance_variable_set("@" + type + "_provisioner_defaults", provisioner_data)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
rescue => e
|
28
|
+
puts "Your config file is missing. Please create the 'nodes.yml' file in the config directory: #{e}"
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
# Ignore any and all YAML blocks with these keys.
|
33
|
+
# Typically, this should be used for any YAML anchors
|
34
|
+
# that may be reused for other Vagrantbox definitions
|
35
|
+
ignore_config = ['default']
|
36
|
+
ignore_config.each { |ignore_key| profiles.delete(ignore_key) }
|
37
|
+
|
38
|
+
profiles.each do |profile, node_config|
|
39
|
+
# Bail out if it is one of our special 'ignore' config blocks
|
40
|
+
config.vm.define profile do |config|
|
41
|
+
# Setup VBox
|
42
|
+
config.vm.box = node_config['vbox']
|
43
|
+
config.vm.box_url = node_config['vbox_url']
|
44
|
+
|
45
|
+
# Configure Hostname
|
46
|
+
host_name = node_config.has_key?("orgname") ? "#{profile.to_s}.#{node_config['orgname']}" : profile.to_s
|
47
|
+
config.vm.host_name = host_name
|
48
|
+
|
49
|
+
if node_config.has_key?('guest')
|
50
|
+
config.vm.guest = node_config['guest']
|
51
|
+
end
|
52
|
+
|
53
|
+
# WinRM specific Configuration
|
54
|
+
if node_config.has_key?('winrm')
|
55
|
+
config.winrm.username = node_config['winrm']['username']
|
56
|
+
config.winrm.password = node_config['winrm']['password']
|
57
|
+
config.winrm.timeout = node_config['winrm']['timeout'] || 1800
|
58
|
+
end
|
59
|
+
|
60
|
+
# Configure memory and CPU
|
61
|
+
config.vm.customize ["modifyvm", :id, "--memory", node_config['memory_size'].to_s] if node_config.has_key?('memory_size')
|
62
|
+
config.vm.customize ["modifyvm", :id, "--cpus", node_config['cpu_count'].to_s] if node_config.has_key?('cpu_count')
|
63
|
+
|
64
|
+
# Configure Network
|
65
|
+
if node_config.has_key?('ip')
|
66
|
+
netmask = node_config.has_key?('netmask') ? node_config['netmask'] : '255.255.255.0'
|
67
|
+
config.vm.network :hostonly, node_config['ip'], :netmask => netmask
|
68
|
+
end
|
69
|
+
|
70
|
+
# Configure any host-based port forwards
|
71
|
+
if node_config.has_key?('ports')
|
72
|
+
node_config['ports'].each { |k,v| config.vm.forward_port(v['guest'], v['host']) }
|
73
|
+
end
|
74
|
+
|
75
|
+
# custom mounts
|
76
|
+
if node_config.has_key?('mounts')
|
77
|
+
node_config['mounts'].each { |desc, mount| config.vm.share_folder("#{desc}","#{mount['guest']}","#{mount['host']}", :create => 'true', :owner => mount.has_key?('owner') ? mount['owner'] : 'vagrant') }
|
78
|
+
end
|
79
|
+
|
80
|
+
# Setup Puppet Provisioner
|
81
|
+
if node_config.has_key?('puppet')
|
82
|
+
# Import any defaults set by the Puppet Provisioner
|
83
|
+
node_config.deep_merge!(@puppet_provisioner_defaults) if !@puppet_provisioner_defaults.nil?
|
84
|
+
|
85
|
+
config.vm.provision :puppet do |puppet|
|
86
|
+
puppet.module_path = node_config['puppet']['modules']
|
87
|
+
puppet.manifests_path = node_config['puppet']['manifests_path']
|
88
|
+
puppet.manifest_file =
|
89
|
+
node_config['puppet'].has_key?('manifest_file') ? node_config['puppet']['manifest_file'] : "#{profile.to_s}.pp"
|
90
|
+
|
91
|
+
# Setup Puppet Graphing
|
92
|
+
if node_config['puppet']['options'].include?('--graph')
|
93
|
+
begin
|
94
|
+
graph_dir = File.join(config_dir,'..','graph')
|
95
|
+
[graph_dir, "#{graph_dir}/#{host_name}"].each { |d| Dir.mkdir(d) if !File.directory?(d) }
|
96
|
+
node_config['puppet']['options'] << "--graphdir=/vagrant/graph/#{host_name}"
|
97
|
+
rescue => e
|
98
|
+
puts "Unable to create Puppet Graph Directory: #{e}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Puppet Options must be the last option to ensure any additions are included
|
103
|
+
puppet.options = node_config['puppet']['options'].join(' ')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Setup Chef Provisioner
|
108
|
+
if node_config.has_key?('chef')
|
109
|
+
# Import any defaults set by the Chef Provisioner
|
110
|
+
node_config.deep_merge!(@chef_provisioner_defaults) if !@chef_provisioner_defaults.nil?
|
111
|
+
|
112
|
+
config.vm.provision :chef_solo do |chef|
|
113
|
+
chef.log_level = node_config['chef']['log_level'].to_sym
|
114
|
+
chef.cookbooks_path = node_config['chef']['cookbooks_path']
|
115
|
+
chef.roles_path = node_config['chef']['roles_path']
|
116
|
+
chef.data_bags_path = node_config['chef']['data_bags_path']
|
117
|
+
node_config['chef']['roles'].each { |role| chef.add_role(role) }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end.curry[cfdir]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
data/lib/vagrant_init.rb
ADDED
data/spec/hitch_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'..','/lib/vagrant-hitch')
|
2
|
+
describe VagrantHitch do
|
3
|
+
it 'should return a proc' do
|
4
|
+
VagrantHitch.up!('.').should be_a(Proc)
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'should require an argument' do
|
8
|
+
expect { VagrantHitch.up! }.to raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should require a valid configuration path' do
|
12
|
+
expect { VagrantHitch.up!('somepath') }.to raise_error
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Aziz Shamim","James Fryman"]
|
5
|
+
gem.email = ["azizshamim@gmail.com", "james@frymanet.com"]
|
6
|
+
gem.description = %q{Creates and use a data driven vagrant environment}
|
7
|
+
gem.summary = %q{Creates and use a data driven vagrant environment}
|
8
|
+
gem.homepage = "https://github.com/fup/vagrant-hitch"
|
9
|
+
|
10
|
+
gem.add_dependency "vagrant"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "vagrant-hitch"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = "0.0.1"
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-hitch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aziz Shamim
|
9
|
+
- James Fryman
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-09-24 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: vagrant
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
description: Creates and use a data driven vagrant environment
|
32
|
+
email:
|
33
|
+
- azizshamim@gmail.com
|
34
|
+
- james@frymanet.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- .gitignore
|
40
|
+
- .rspec
|
41
|
+
- LICENSE
|
42
|
+
- README.mkd
|
43
|
+
- Rakefile
|
44
|
+
- example/Vagrantfile
|
45
|
+
- example/config/nodes.yml
|
46
|
+
- example/config/provisioner_chef.yml
|
47
|
+
- example/config/provisioner_puppet.yml
|
48
|
+
- example/config/provisioner_puppet_server.yml
|
49
|
+
- lib/deep_merge.rb
|
50
|
+
- lib/vagrant-hitch.rb
|
51
|
+
- lib/vagrant_init.rb
|
52
|
+
- spec/hitch_spec.rb
|
53
|
+
- vagrant-hitch.gemspec
|
54
|
+
homepage: https://github.com/fup/vagrant-hitch
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.24
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Creates and use a data driven vagrant environment
|
78
|
+
test_files:
|
79
|
+
- spec/hitch_spec.rb
|