vagrant-hitch 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +6 -2
- data/Rakefile +3 -1
- data/example/config/nodes.yml +32 -6
- data/example/config/provisioner_shell.yml +4 -0
- data/example/script/example.sh +2 -0
- data/lib/vagrant-hitch.rb +180 -121
- data/spec/hitch_spec.rb +93 -3
- data/vagrant-hitch.gemspec +2 -1
- metadata +76 -71
- data/lib/deep_merge.rb +0 -26
data/Gemfile.lock
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vagrant-hitch (0.0
|
4
|
+
vagrant-hitch (0.1.0)
|
5
5
|
backports
|
6
|
+
deep_merge
|
6
7
|
vagrant
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: http://rubygems.org/
|
10
11
|
specs:
|
11
12
|
archive-tar-minitar (0.5.2)
|
12
|
-
backports (2.
|
13
|
+
backports (2.8.2)
|
13
14
|
childprocess (0.3.7)
|
14
15
|
ffi (~> 1.0, >= 1.0.6)
|
16
|
+
deep_merge (1.0.0)
|
15
17
|
diff-lcs (1.1.3)
|
16
18
|
erubis (2.7.0)
|
17
19
|
ffi (1.3.1)
|
@@ -21,6 +23,7 @@ GEM
|
|
21
23
|
net-scp (1.0.4)
|
22
24
|
net-ssh (>= 1.99.1)
|
23
25
|
net-ssh (2.2.2)
|
26
|
+
rake (10.0.3)
|
24
27
|
rspec (2.11.0)
|
25
28
|
rspec-core (~> 2.11.0)
|
26
29
|
rspec-expectations (~> 2.11.0)
|
@@ -43,5 +46,6 @@ PLATFORMS
|
|
43
46
|
ruby
|
44
47
|
|
45
48
|
DEPENDENCIES
|
49
|
+
rake
|
46
50
|
rspec
|
47
51
|
vagrant-hitch!
|
data/Rakefile
CHANGED
@@ -3,6 +3,8 @@ require 'rspec/core/rake_task'
|
|
3
3
|
|
4
4
|
task :default => [:test]
|
5
5
|
|
6
|
+
task :spec => :test
|
7
|
+
|
6
8
|
desc "run all functional specs in this ruby environment"
|
7
9
|
RSpec::Core::RakeTask.new(:test) do |t|
|
8
10
|
t.pattern = 'spec/*_spec.rb'
|
@@ -17,7 +19,7 @@ end
|
|
17
19
|
|
18
20
|
desc "run the specs through all the supported rubies"
|
19
21
|
task :rubies do
|
20
|
-
system("rvm 1.8.7-p370,1.9.3-p194 do rake
|
22
|
+
system("rvm 1.8.7-p370,1.9.3-p194 do rake test")
|
21
23
|
end
|
22
24
|
|
23
25
|
desc "set up all ruby environments"
|
data/example/config/nodes.yml
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
default: &default
|
2
|
+
cpu_count: 2
|
3
|
+
memory_size: 512
|
2
4
|
vbox: vbox-name
|
3
5
|
orgname: vagrant.test
|
4
6
|
puppet:
|
5
7
|
manifest_file: site.pp
|
8
|
+
mounts:
|
9
|
+
webapp:
|
10
|
+
host: ./
|
11
|
+
guest: /opt/www/
|
6
12
|
ports:
|
7
13
|
http:
|
8
14
|
host: 10080
|
@@ -10,15 +16,35 @@ default: &default
|
|
10
16
|
https:
|
11
17
|
host: 10443
|
12
18
|
guest: 443
|
13
|
-
mysql:
|
14
|
-
host: 13310
|
15
|
-
guest: 3306
|
16
|
-
tomcat:
|
17
|
-
host: 18080
|
18
|
-
guest: 8080
|
19
19
|
default_app: &default_app
|
20
20
|
web_default: &web_default
|
21
21
|
test1:
|
22
22
|
<<: *default
|
23
|
+
# Mounts do not merge, they only override because YAML anchors don't merge
|
24
|
+
ip: 10.10.10.10
|
25
|
+
puppet:
|
26
|
+
manifest_file: test1.pp
|
27
|
+
mounts:
|
28
|
+
webapp:
|
29
|
+
host: ./
|
30
|
+
guest: /opt/www/
|
31
|
+
database:
|
32
|
+
host: ./
|
33
|
+
guest: /opt/mysql/database
|
34
|
+
# Ports do not merge, they only override because YAML anchors don't merge
|
35
|
+
ports:
|
36
|
+
mysql:
|
37
|
+
host: 13310
|
38
|
+
guest: 3306
|
23
39
|
test2:
|
24
40
|
<<: *default
|
41
|
+
shell:
|
42
|
+
puppet:
|
43
|
+
ports:
|
44
|
+
tomcat:
|
45
|
+
host: 18080
|
46
|
+
guest: 8080
|
47
|
+
mounts:
|
48
|
+
tomcat:
|
49
|
+
host: ./
|
50
|
+
guest: /opt/tomcat/webapp
|
data/lib/vagrant-hitch.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'vagrant'
|
3
3
|
require 'backports'
|
4
|
-
require
|
4
|
+
require 'deep_merge'
|
5
|
+
require 'pry'
|
5
6
|
|
6
7
|
module VagrantHitch
|
7
8
|
def self.validate(cfdir)
|
@@ -11,6 +12,181 @@ module VagrantHitch
|
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
15
|
+
def self.setup_dns(profile, node_config, config)
|
16
|
+
# Vagrant-DNS Support
|
17
|
+
if node_config['dns']
|
18
|
+
if node_config['dns']['tld']
|
19
|
+
config.dns.tld = node_config['dns']['tld']
|
20
|
+
end
|
21
|
+
|
22
|
+
if node_config['dns']['patterns']
|
23
|
+
config.dns.patterns = node_config['dns']['patterns']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.setup_vbox(profile, node_config, config)
|
29
|
+
config.vm.box = node_config['vbox']
|
30
|
+
config.vm.box_url = node_config['vbox_url']
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.setup_hostname(profile, node_config, config)
|
34
|
+
# Setup VBox
|
35
|
+
# Configure Hostname
|
36
|
+
hostname = node_config.has_key?('orgname') ? "#{profile.to_s}.#{node_config['orgname']}" : "#{profile.to_s}.vagrant"
|
37
|
+
config.vm.host_name = hostname
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.setup_cpu(profile, node_config, config)
|
41
|
+
# Configure CPU
|
42
|
+
config.vm.customize ["modifyvm", :id, "--cpus", node_config['cpu_count'].to_s] if node_config.has_key?('cpu_count')
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.setup_memory(profile, node_config, config)
|
46
|
+
# Configure Memory
|
47
|
+
config.vm.customize ["modifyvm", :id, "--memory", node_config['memory_size'].to_s] if node_config.has_key?('memory_size')
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.setup_network(profile, node_config, config)
|
51
|
+
# Configure Network
|
52
|
+
if node_config.has_key?('ip')
|
53
|
+
netmask = node_config.has_key?('netmask') ? node_config['netmask'] : '255.255.255.0'
|
54
|
+
config.vm.network :hostonly, node_config['ip'], :netmask => netmask
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.setup_guest(profile, node_config, config)
|
59
|
+
if node_config.has_key?('guest')
|
60
|
+
config.vm.guest = node_config['guest']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.setup_ports(profile, node_config, config)
|
65
|
+
# Configure any host-based port forwards
|
66
|
+
if node_config.has_key?('ports')
|
67
|
+
node_config['ports'].each { |k,v| config.vm.forward_port(v['guest'], v['host']) }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.setup_winrm(profile, node_config, config)
|
72
|
+
# WinRM specific Configuration
|
73
|
+
if node_config.has_key?('winrm')
|
74
|
+
config.winrm.username = node_config['winrm']['username']
|
75
|
+
config.winrm.password = node_config['winrm']['password']
|
76
|
+
config.winrm.timeout = node_config['winrm']['timeout'] || 1800
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.setup_mounts(profile, node_config, config)
|
81
|
+
# custom mounts
|
82
|
+
if node_config.has_key?('mounts')
|
83
|
+
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') }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.setup_provisioners(profile, node_config, config, config_dir)
|
88
|
+
# Setup Shell provisioner
|
89
|
+
if node_config.has_key?('shell')
|
90
|
+
node_config.deep_merge!(@shell_provisioner_defaults) if !@shell_provisioner_defaults.nil?
|
91
|
+
config.vm.provision :shell do |shell|
|
92
|
+
shell.inline = node_config['shell']['inline'] if node_config['shell'].has_key?('inline')
|
93
|
+
shell.args = node_config['shell']['args'] if node_config['shell'].has_key?('args')
|
94
|
+
shell.path = node_config['shell']['path'] if node_config['shell'].has_key?('path')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Setup Puppet Provisioner
|
99
|
+
if node_config.has_key?('puppet')
|
100
|
+
# Import any defaults set by the Puppet Provisioner
|
101
|
+
node_config.deep_merge!(@puppet_provisioner_defaults) if !@puppet_provisioner_defaults.nil?
|
102
|
+
|
103
|
+
config.vm.provision :puppet do |puppet|
|
104
|
+
puppet.module_path = node_config['puppet']['modules']
|
105
|
+
puppet.manifests_path = node_config['puppet']['manifests_path']
|
106
|
+
puppet.manifest_file =
|
107
|
+
node_config['puppet'].has_key?('manifest_file') ? node_config['puppet']['manifest_file'] : "#{profile.to_s}.pp"
|
108
|
+
|
109
|
+
# Setup Puppet Graphing
|
110
|
+
if node_config['puppet']['options'].include?('--graph')
|
111
|
+
begin
|
112
|
+
graph_dir = File.join(config_dir,'..','graph')
|
113
|
+
[graph_dir, "#{graph_dir}/#{config.vm.host_name}"].each { |d| Dir.mkdir(d) if !File.directory?(d) }
|
114
|
+
node_config['puppet']['options'] << "--graphdir=/vagrant/graph/#{config.vm.host_name}"
|
115
|
+
rescue => e
|
116
|
+
puts "Unable to create Puppet Graph Directory: #{e}"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Puppet Options must be the last option to ensure any additions are included
|
121
|
+
puppet.options = node_config['puppet']['options'].join(' ')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Setup Chef Provisioner
|
126
|
+
if node_config.has_key?('chef')
|
127
|
+
# Import any defaults set by the Chef Provisioner
|
128
|
+
node_config.deep_merge!(@chef_provisioner_defaults) if !@chef_provisioner_defaults.nil?
|
129
|
+
|
130
|
+
config.vm.provision :chef_solo do |chef|
|
131
|
+
chef.log_level = node_config['chef']['log_level'].to_sym
|
132
|
+
chef.cookbooks_path = node_config['chef']['cookbooks_path']
|
133
|
+
chef.roles_path = node_config['chef']['roles_path']
|
134
|
+
chef.data_bags_path = node_config['chef']['data_bags_path']
|
135
|
+
node_config['chef']['roles'].each { |role| chef.add_role(role) }
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Setup Puppet Server Provisioner
|
140
|
+
if node_config.has_key?('puppet_server')
|
141
|
+
# Import any defaults set by the Puppet Server Provisioner
|
142
|
+
node_config.deep_merge!(@puppet_server_provisioner_defaults) if !@puppet_server_provisioner_defaults.nil?
|
143
|
+
|
144
|
+
config.vm.provision :puppet_server do |puppet|
|
145
|
+
puppet.puppet_server = node_config['puppet_server']['server']
|
146
|
+
puppet.puppet_node = config.vm.host_name
|
147
|
+
|
148
|
+
# Setup Puppet Graphing
|
149
|
+
if node_config['puppet_server']['options'].include?('--graph')
|
150
|
+
begin
|
151
|
+
graph_dir = File.join(config_dir,'..','graph')
|
152
|
+
[graph_dir, "#{graph_dir}/#{config.vm.host_name}"].each { |d| Dir.mkdir(d) if !File.directory?(d) }
|
153
|
+
node_config['puppet_server']['options'] << "--graphdir=/vagrant/graph/#{config.vm.host_name}"
|
154
|
+
rescue => e
|
155
|
+
puts "Unable to create Puppet Graph Directory: #{e}"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Puppet Options must be the last option to ensure any additions are included
|
160
|
+
puppet.options = node_config['puppet_server']['options'].join(' ')
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
def self.configure_node(profile, node_config, config, config_dir)
|
167
|
+
# Bail out if it is one of our special 'ignore' config blocks
|
168
|
+
config.vm.define profile do |config|
|
169
|
+
# Setup the environment
|
170
|
+
self.setup_dns(profile, node_config, config)
|
171
|
+
self.setup_vbox(profile, node_config, config)
|
172
|
+
|
173
|
+
# set up the server
|
174
|
+
self.setup_hostname(profile, node_config, config)
|
175
|
+
self.setup_cpu(profile, node_config, config)
|
176
|
+
self.setup_memory(profile, node_config, config)
|
177
|
+
self.setup_network(profile, node_config, config)
|
178
|
+
self.setup_guest(profile, node_config, config)
|
179
|
+
self.setup_winrm(profile, node_config, config)
|
180
|
+
|
181
|
+
# set up the integrations
|
182
|
+
self.setup_ports(profile, node_config, config)
|
183
|
+
self.setup_mounts(profile, node_config, config)
|
184
|
+
|
185
|
+
# set up the provisioners
|
186
|
+
self.setup_provisioners(profile, node_config, config, config_dir)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
14
190
|
def self.up!(cfdir)
|
15
191
|
self.validate(cfdir)
|
16
192
|
return lambda do |config_dir, config|
|
@@ -18,7 +194,7 @@ module VagrantHitch
|
|
18
194
|
begin
|
19
195
|
profiles = YAML::load_file(File.join(config_dir,'nodes.yml'))
|
20
196
|
|
21
|
-
['chef',
|
197
|
+
['shell','chef','puppet','puppet_server'].each do |type|
|
22
198
|
if File.exists?(File.join(config_dir, "provisioner_#{type}.yml"))
|
23
199
|
provisioner_data = YAML::load_file(File.join(config_dir, "provisioner_#{type}.yml"))
|
24
200
|
instance_variable_set("@" + type + "_provisioner_defaults", provisioner_data)
|
@@ -37,126 +213,9 @@ module VagrantHitch
|
|
37
213
|
true if ignore_config.find_index { |ignore_key| p.include?(ignore_key) }
|
38
214
|
end
|
39
215
|
|
216
|
+
# Set up each profile
|
40
217
|
profiles.each do |profile, node_config|
|
41
|
-
|
42
|
-
config.vm.define profile do |config|
|
43
|
-
|
44
|
-
# Vagrant-DNS Support
|
45
|
-
if node_config['dns']
|
46
|
-
if node_config['dns']['tld']
|
47
|
-
config.dns.tld = node_config['dns']['tld']
|
48
|
-
end
|
49
|
-
|
50
|
-
if node_config['dns']['patterns']
|
51
|
-
config.dns.patterns = node_config['dns']['patterns']
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# Setup VBox
|
56
|
-
config.vm.box = node_config['vbox']
|
57
|
-
config.vm.box_url = node_config['vbox_url']
|
58
|
-
|
59
|
-
# Configure Hostname
|
60
|
-
hostname = node_config.has_key?('orgname') ? "#{profile.to_s}.#{node_config['orgname']}" : "#{profile.to_s}.vagrant"
|
61
|
-
config.vm.host_name = hostname
|
62
|
-
|
63
|
-
if node_config.has_key?('guest')
|
64
|
-
config.vm.guest = node_config['guest']
|
65
|
-
end
|
66
|
-
|
67
|
-
# WinRM specific Configuration
|
68
|
-
if node_config.has_key?('winrm')
|
69
|
-
config.winrm.username = node_config['winrm']['username']
|
70
|
-
config.winrm.password = node_config['winrm']['password']
|
71
|
-
config.winrm.timeout = node_config['winrm']['timeout'] || 1800
|
72
|
-
end
|
73
|
-
|
74
|
-
# Configure memory and CPU
|
75
|
-
config.vm.customize ["modifyvm", :id, "--memory", node_config['memory_size'].to_s] if node_config.has_key?('memory_size')
|
76
|
-
config.vm.customize ["modifyvm", :id, "--cpus", node_config['cpu_count'].to_s] if node_config.has_key?('cpu_count')
|
77
|
-
|
78
|
-
# Configure Network
|
79
|
-
if node_config.has_key?('ip')
|
80
|
-
netmask = node_config.has_key?('netmask') ? node_config['netmask'] : '255.255.255.0'
|
81
|
-
config.vm.network :hostonly, node_config['ip'], :netmask => netmask
|
82
|
-
end
|
83
|
-
|
84
|
-
# Configure any host-based port forwards
|
85
|
-
if node_config.has_key?('ports')
|
86
|
-
node_config['ports'].each { |k,v| config.vm.forward_port(v['guest'], v['host']) }
|
87
|
-
end
|
88
|
-
|
89
|
-
# custom mounts
|
90
|
-
if node_config.has_key?('mounts')
|
91
|
-
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') }
|
92
|
-
end
|
93
|
-
|
94
|
-
# Setup Puppet Provisioner
|
95
|
-
if node_config.has_key?('puppet')
|
96
|
-
# Import any defaults set by the Puppet Provisioner
|
97
|
-
node_config.deep_merge!(@puppet_provisioner_defaults) if !@puppet_provisioner_defaults.nil?
|
98
|
-
|
99
|
-
config.vm.provision :puppet do |puppet|
|
100
|
-
puppet.module_path = node_config['puppet']['modules']
|
101
|
-
puppet.manifests_path = node_config['puppet']['manifests_path']
|
102
|
-
puppet.manifest_file =
|
103
|
-
node_config['puppet'].has_key?('manifest_file') ? node_config['puppet']['manifest_file'] : "#{profile.to_s}.pp"
|
104
|
-
|
105
|
-
# Setup Puppet Graphing
|
106
|
-
if node_config['puppet']['options'].include?('--graph')
|
107
|
-
begin
|
108
|
-
graph_dir = File.join(config_dir,'..','graph')
|
109
|
-
[graph_dir, "#{graph_dir}/#{hostname}"].each { |d| Dir.mkdir(d) if !File.directory?(d) }
|
110
|
-
node_config['puppet']['options'] << "--graphdir=/vagrant/graph/#{hostname}"
|
111
|
-
rescue => e
|
112
|
-
puts "Unable to create Puppet Graph Directory: #{e}"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# Puppet Options must be the last option to ensure any additions are included
|
117
|
-
puppet.options = node_config['puppet']['options'].join(' ')
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# Setup Puppet Server Provisioner
|
122
|
-
if node_config.has_key?('puppet_server')
|
123
|
-
# Import any defaults set by the Puppet Server Provisioner
|
124
|
-
node_config.deep_merge!(@puppet_server_provisioner_defaults) if !@puppet_server_provisioner_defaults.nil?
|
125
|
-
|
126
|
-
config.vm.provision :puppet_server do |puppet|
|
127
|
-
puppet.puppet_server = node_config['puppet_server']['server']
|
128
|
-
puppet.puppet_node = hostname
|
129
|
-
|
130
|
-
# Setup Puppet Graphing
|
131
|
-
if node_config['puppet_server']['options'].include?('--graph')
|
132
|
-
begin
|
133
|
-
graph_dir = File.join(config_dir,'..','graph')
|
134
|
-
[graph_dir, "#{graph_dir}/#{hostname}"].each { |d| Dir.mkdir(d) if !File.directory?(d) }
|
135
|
-
node_config['puppet_server']['options'] << "--graphdir=/vagrant/graph/#{hostname}"
|
136
|
-
rescue => e
|
137
|
-
puts "Unable to create Puppet Graph Directory: #{e}"
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
# Puppet Options must be the last option to ensure any additions are included
|
142
|
-
puppet.options = node_config['puppet_server']['options'].join(' ')
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
# Setup Chef Provisioner
|
147
|
-
if node_config.has_key?('chef')
|
148
|
-
# Import any defaults set by the Chef Provisioner
|
149
|
-
node_config.deep_merge!(@chef_provisioner_defaults) if !@chef_provisioner_defaults.nil?
|
150
|
-
|
151
|
-
config.vm.provision :chef_solo do |chef|
|
152
|
-
chef.log_level = node_config['chef']['log_level'].to_sym
|
153
|
-
chef.cookbooks_path = node_config['chef']['cookbooks_path']
|
154
|
-
chef.roles_path = node_config['chef']['roles_path']
|
155
|
-
chef.data_bags_path = node_config['chef']['data_bags_path']
|
156
|
-
node_config['chef']['roles'].each { |role| chef.add_role(role) }
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
218
|
+
self.configure_node(profile, node_config, config, config_dir)
|
160
219
|
end
|
161
220
|
end.curry[cfdir]
|
162
221
|
end
|
data/spec/hitch_spec.rb
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
require 'tmpdir'
|
2
|
+
require 'ap'
|
2
3
|
|
3
4
|
require File.join(File.dirname(__FILE__),'..','/lib/vagrant-hitch')
|
5
|
+
describe 'Hash' do
|
6
|
+
let(:a) { {:string => "a", :array => [ 0,1,2 ], :hash => { :one => '1', :two => '2' } } }
|
7
|
+
let(:b) { {:string => "b", :array => [ 3,4,5 ], :hash => { :three => '3', :four => '4' } } }
|
8
|
+
let(:ab) { {:string => "b", :array => [0,1,2,3,4,5 ], :hash => {:one => '1', :two => '2', :three => '3', :four => '4' } } }
|
9
|
+
|
10
|
+
it 'Hashes should have deep merge available' do
|
11
|
+
a.should respond_to(:deep_merge)
|
12
|
+
a.should respond_to(:deep_merge!)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'merges should work as expected' do
|
16
|
+
a.deep_merge!(b).should eql(ab)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
4
20
|
describe VagrantHitch do
|
5
21
|
it 'should return a proc' do
|
6
22
|
VagrantHitch.up!('.').should be_a(Proc)
|
@@ -14,26 +30,100 @@ describe VagrantHitch do
|
|
14
30
|
expect { VagrantHitch.up!('somepath') }.to raise_error
|
15
31
|
end
|
16
32
|
|
33
|
+
|
17
34
|
context "with a valid Vagrantfile" do
|
18
35
|
# set up Vagrantfile
|
19
36
|
before(:all) do
|
20
37
|
rootdir = File.join(File.dirname(__FILE__),'..')
|
21
|
-
tempdir = Dir.tmpdir
|
38
|
+
@tempdir = Dir.tmpdir
|
22
39
|
vagrantfile = <<-HERE.gsub(/^ {6}/, '')
|
23
40
|
require '#{rootdir}/lib/vagrant_init.rb'
|
24
41
|
Vagrant::Config.run &VagrantHitch.up!(File.join('#{rootdir}','example','config'))
|
25
42
|
HERE
|
26
43
|
# create new Vagrantfile in ../tmp
|
27
|
-
File.open(File.join(tempdir,"Vagrantfile"), "w") {|f| f.write(vagrantfile) }
|
28
|
-
Dir.chdir(tempdir)
|
44
|
+
File.open(File.join(@tempdir,"Vagrantfile"), "w") {|f| f.write(vagrantfile) }
|
45
|
+
Dir.chdir(@tempdir)
|
29
46
|
end
|
30
47
|
|
31
48
|
# clean up the temporary directory
|
32
49
|
after(:all) do
|
33
50
|
end
|
34
51
|
|
52
|
+
context 'single vagrant box configuration' do
|
53
|
+
let(:vagrant_env) { ::Vagrant::Environment.new(:cwd => @tempdir) }
|
54
|
+
|
55
|
+
it 'should configure cpu' do
|
56
|
+
vagrant_env.vms_ordered.first.config.vm.customizations.should include(["modifyvm", :id, "--cpus", "2"])
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should configure memory' do
|
60
|
+
vagrant_env.vms_ordered.first.config.vm.customizations.should include(["modifyvm", :id, "--memory", "512"])
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should have a hostname' do
|
64
|
+
vagrant_env.vms_ordered.first.config.vm.host_name.should eql("test1.vagrant.test")
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should have a network' do
|
68
|
+
vagrant_env.vms_ordered.first.config.vm.networks.should include([:hostonly, ["10.10.10.10", {:netmask=>"255.255.255.0"}]])
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should have dns' do
|
72
|
+
pending("what does config.dns.tld and config.dns.patterns provide?")
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should have a provisioner' do
|
76
|
+
vagrant_env.vms_ordered.first.config.vm.provisioners.first.provisioner.should eql(Vagrant::Provisioners::Puppet)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should have network ports forward' do
|
80
|
+
vagrant_env.vms_ordered.first.config.vm.forwarded_ports.should include({:name=>"ssh", :guestport=>22,
|
81
|
+
:hostport=>2222, :protocol=>:tcp,
|
82
|
+
:adapter=>1, :auto=>true})
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should mounted folders' do
|
86
|
+
vagrant_env.vms_ordered.first.config.vm.shared_folders.should have(3).items
|
87
|
+
vagrant_env.vms_ordered.first.config.vm.shared_folders.should include(
|
88
|
+
"webapp"=> {:guestpath=>"/opt/www/", :hostpath=>"./", :create=>"true",
|
89
|
+
:owner=>"vagrant", :group=>nil, :nfs=>false,
|
90
|
+
:transient=>false, :extra=>nil},
|
91
|
+
"database"=> {:guestpath=>"/opt/mysql/database", :hostpath=>"./",
|
92
|
+
:create=>"true", :owner=>"vagrant", :group=>nil,
|
93
|
+
:nfs=>false, :transient=>false, :extra=>nil},
|
94
|
+
"v-root"=> {:guestpath=>"/vagrant", :hostpath=>".", :create=>false, :owner=>nil, :group=>nil, :nfs=>false,
|
95
|
+
:transient=>false, :extra=>nil}
|
96
|
+
)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'property merging' do
|
101
|
+
let(:vagrant_env) { ::Vagrant::Environment.new(:cwd => @tempdir) }
|
102
|
+
it 'should create a vagrant environment' do
|
103
|
+
vagrant_env.should_not be_nil
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should merge the default mounts properly' do
|
107
|
+
pending "this feature either uses YAML anchors or code-based 'default' merge"
|
108
|
+
#vagrant_env.vms_ordered.first.config.vm.shared_folders.should have(3).items
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should merge the default provisioner settings properly' do
|
112
|
+
puppet_provisioner = vagrant_env.vms_ordered.first.config.vm.provisioners.first
|
113
|
+
puppet_provisioner.provisioner.should eql(Vagrant::Provisioners::Puppet)
|
114
|
+
puppet_provisioner.config.module_path.should have(2).items
|
115
|
+
puppet_provisioner.config.manifests_path.should eql("../manifests")
|
116
|
+
puppet_provisioner.config.manifest_file.should eql("test1.pp")
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should configure multiple provisioners' do
|
120
|
+
vagrant_env.vms_ordered.last.config.vm.provisioners.should have(2).items
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
35
124
|
it 'should not include the default node information' do
|
36
125
|
output = Array.new
|
126
|
+
# should this be fixed to test the environment instead of output from a piped command?
|
37
127
|
IO.popen("vagrant status") { |io| output = io.readlines.collect { |l| l.chomp } }
|
38
128
|
output.should include("test1 not created","test2 not created")
|
39
129
|
output.should_not include("default not created")
|
data/vagrant-hitch.gemspec
CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
|
10
10
|
gem.add_dependency "vagrant"
|
11
11
|
gem.add_dependency "backports"
|
12
|
+
gem.add_dependency "deep_merge"
|
12
13
|
gem.add_development_dependency "rspec"
|
13
14
|
|
14
15
|
gem.files = `git ls-files`.split($\)
|
@@ -16,5 +17,5 @@ Gem::Specification.new do |gem|
|
|
16
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
18
|
gem.name = "vagrant-hitch"
|
18
19
|
gem.require_paths = ["lib"]
|
19
|
-
gem.version = "0.1.
|
20
|
+
gem.version = "0.1.1"
|
20
21
|
end
|
metadata
CHANGED
@@ -1,76 +1,89 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-hitch
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Aziz Shamim
|
14
9
|
- James Fryman
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: vagrant
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
25
18
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
33
23
|
type: :runtime
|
34
|
-
|
35
|
-
|
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
|
+
- !ruby/object:Gem::Dependency
|
36
32
|
name: backports
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
37
40
|
prerelease: false
|
38
|
-
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: deep_merge
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
type: :runtime
|
48
|
-
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: rspec
|
51
56
|
prerelease: false
|
52
|
-
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rspec
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
53
66
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
version: "0"
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
61
71
|
type: :development
|
62
|
-
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
63
79
|
description: Creates and use a data driven vagrant environment
|
64
|
-
email:
|
80
|
+
email:
|
65
81
|
- azizshamim@gmail.com
|
66
82
|
- james@frymanet.com
|
67
83
|
executables: []
|
68
|
-
|
69
84
|
extensions: []
|
70
|
-
|
71
85
|
extra_rdoc_files: []
|
72
|
-
|
73
|
-
files:
|
86
|
+
files:
|
74
87
|
- .gitignore
|
75
88
|
- .rspec
|
76
89
|
- .travis.yml
|
@@ -84,43 +97,35 @@ files:
|
|
84
97
|
- example/config/provisioner_chef.yml
|
85
98
|
- example/config/provisioner_puppet.yml
|
86
99
|
- example/config/provisioner_puppet_server.yml
|
87
|
-
-
|
100
|
+
- example/config/provisioner_shell.yml
|
101
|
+
- example/script/example.sh
|
88
102
|
- lib/vagrant-hitch.rb
|
89
103
|
- lib/vagrant_init.rb
|
90
104
|
- spec/hitch_spec.rb
|
91
105
|
- vagrant-hitch.gemspec
|
92
106
|
homepage: https://github.com/fup/vagrant-hitch
|
93
107
|
licenses: []
|
94
|
-
|
95
108
|
post_install_message:
|
96
109
|
rdoc_options: []
|
97
|
-
|
98
|
-
require_paths:
|
110
|
+
require_paths:
|
99
111
|
- lib
|
100
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
113
|
none: false
|
102
|
-
requirements:
|
103
|
-
- -
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
|
106
|
-
|
107
|
-
- 0
|
108
|
-
version: "0"
|
109
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
119
|
none: false
|
111
|
-
requirements:
|
112
|
-
- -
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
|
115
|
-
segments:
|
116
|
-
- 0
|
117
|
-
version: "0"
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
118
124
|
requirements: []
|
119
|
-
|
120
125
|
rubyforge_project:
|
121
126
|
rubygems_version: 1.8.24
|
122
127
|
signing_key:
|
123
128
|
specification_version: 3
|
124
129
|
summary: Creates and use a data driven vagrant environment
|
125
|
-
test_files:
|
130
|
+
test_files:
|
126
131
|
- spec/hitch_spec.rb
|
data/lib/deep_merge.rb
DELETED
@@ -1,26 +0,0 @@
|
|
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
|