vagrant 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -4
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/bin/vagrant +5 -13
- data/config/default.rb +1 -0
- data/keys/README.md +8 -1
- data/keys/vagrant.ppk +26 -0
- data/lib/vagrant.rb +3 -3
- data/lib/vagrant/actions/base.rb +15 -4
- data/lib/vagrant/actions/box/add.rb +1 -1
- data/lib/vagrant/actions/box/download.rb +72 -66
- data/lib/vagrant/actions/box/unpackage.rb +1 -4
- data/lib/vagrant/actions/runner.rb +1 -1
- data/lib/vagrant/actions/vm/boot.rb +5 -7
- data/lib/vagrant/actions/vm/customize.rb +2 -2
- data/lib/vagrant/actions/vm/destroy.rb +2 -2
- data/lib/vagrant/actions/vm/down.rb +7 -0
- data/lib/vagrant/actions/vm/export.rb +10 -4
- data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
- data/lib/vagrant/actions/vm/halt.rb +5 -3
- data/lib/vagrant/actions/vm/import.rb +10 -3
- data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
- data/lib/vagrant/actions/vm/package.rb +33 -10
- data/lib/vagrant/actions/vm/provision.rb +4 -4
- data/lib/vagrant/actions/vm/reload.rb +1 -1
- data/lib/vagrant/actions/vm/resume.rb +1 -1
- data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
- data/lib/vagrant/actions/vm/start.rb +3 -2
- data/lib/vagrant/actions/vm/suspend.rb +2 -2
- data/lib/vagrant/actions/vm/up.rb +7 -17
- data/lib/vagrant/active_list.rb +52 -45
- data/lib/vagrant/box.rb +18 -11
- data/lib/vagrant/busy.rb +7 -0
- data/lib/vagrant/command.rb +27 -0
- data/lib/vagrant/commands/base.rb +163 -0
- data/lib/vagrant/commands/box.rb +16 -0
- data/lib/vagrant/commands/box/add.rb +24 -0
- data/lib/vagrant/commands/box/list.rb +30 -0
- data/lib/vagrant/commands/box/remove.rb +31 -0
- data/lib/vagrant/commands/destroy.rb +23 -0
- data/lib/vagrant/commands/down.rb +16 -0
- data/lib/vagrant/commands/halt.rb +23 -0
- data/lib/vagrant/commands/init.rb +32 -0
- data/lib/vagrant/commands/package.rb +46 -0
- data/lib/vagrant/commands/reload.rb +22 -0
- data/lib/vagrant/commands/resume.rb +22 -0
- data/lib/vagrant/commands/ssh.rb +22 -0
- data/lib/vagrant/commands/ssh_config.rb +30 -0
- data/lib/vagrant/commands/status.rb +58 -0
- data/lib/vagrant/commands/suspend.rb +23 -0
- data/lib/vagrant/commands/up.rb +26 -0
- data/lib/vagrant/config.rb +21 -11
- data/lib/vagrant/downloaders/file.rb +5 -5
- data/lib/vagrant/downloaders/http.rb +10 -15
- data/lib/vagrant/environment.rb +259 -0
- data/lib/vagrant/provisioners/base.rb +7 -0
- data/lib/vagrant/provisioners/chef.rb +24 -9
- data/lib/vagrant/provisioners/chef_server.rb +23 -48
- data/lib/vagrant/provisioners/chef_solo.rb +48 -22
- data/lib/vagrant/ssh.rb +95 -46
- data/lib/vagrant/util.rb +2 -2
- data/lib/vagrant/util/errors.rb +36 -0
- data/lib/vagrant/util/platform.rb +12 -0
- data/lib/vagrant/util/progress_meter.rb +33 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/vm.rb +1 -0
- data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
- data/templates/chef_server_client.erb +16 -0
- data/templates/chef_solo_solo.erb +4 -0
- data/templates/errors.yml +157 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/ssh_config.erb +7 -0
- data/test/test_helper.rb +12 -15
- data/test/vagrant/actions/box/add_test.rb +1 -2
- data/test/vagrant/actions/box/destroy_test.rb +0 -1
- data/test/vagrant/actions/box/download_test.rb +40 -15
- data/test/vagrant/actions/box/unpackage_test.rb +2 -3
- data/test/vagrant/actions/collection_test.rb +8 -5
- data/test/vagrant/actions/runner_test.rb +8 -6
- data/test/vagrant/actions/vm/boot_test.rb +12 -11
- data/test/vagrant/actions/vm/customize_test.rb +2 -3
- data/test/vagrant/actions/vm/destroy_test.rb +2 -3
- data/test/vagrant/actions/vm/down_test.rb +16 -3
- data/test/vagrant/actions/vm/export_test.rb +4 -5
- data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
- data/test/vagrant/actions/vm/halt_test.rb +8 -2
- data/test/vagrant/actions/vm/import_test.rb +5 -5
- data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
- data/test/vagrant/actions/vm/package_test.rb +60 -22
- data/test/vagrant/actions/vm/provision_test.rb +7 -16
- data/test/vagrant/actions/vm/reload_test.rb +3 -2
- data/test/vagrant/actions/vm/resume_test.rb +0 -1
- data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
- data/test/vagrant/actions/vm/start_test.rb +10 -3
- data/test/vagrant/actions/vm/suspend_test.rb +1 -2
- data/test/vagrant/actions/vm/up_test.rb +19 -11
- data/test/vagrant/active_list_test.rb +148 -129
- data/test/vagrant/box_test.rb +26 -14
- data/test/vagrant/busy_test.rb +15 -6
- data/test/vagrant/command_test.rb +53 -0
- data/test/vagrant/commands/base_test.rb +118 -0
- data/test/vagrant/commands/box/add_test.rb +34 -0
- data/test/vagrant/commands/box/list_test.rb +32 -0
- data/test/vagrant/commands/box/remove_test.rb +41 -0
- data/test/vagrant/commands/destroy_test.rb +32 -0
- data/test/vagrant/commands/down_test.rb +17 -0
- data/test/vagrant/commands/halt_test.rb +28 -0
- data/test/vagrant/commands/init_test.rb +55 -0
- data/test/vagrant/commands/package_test.rb +84 -0
- data/test/vagrant/commands/reload_test.rb +28 -0
- data/test/vagrant/commands/resume_test.rb +33 -0
- data/test/vagrant/commands/ssh_config_test.rb +54 -0
- data/test/vagrant/commands/ssh_test.rb +32 -0
- data/test/vagrant/commands/status_test.rb +20 -0
- data/test/vagrant/commands/suspend_test.rb +33 -0
- data/test/vagrant/commands/up_test.rb +41 -0
- data/test/vagrant/config_test.rb +42 -17
- data/test/vagrant/downloaders/file_test.rb +7 -0
- data/test/vagrant/downloaders/http_test.rb +12 -0
- data/test/vagrant/environment_test.rb +595 -0
- data/test/vagrant/provisioners/base_test.rb +7 -1
- data/test/vagrant/provisioners/chef_server_test.rb +41 -51
- data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
- data/test/vagrant/provisioners/chef_test.rb +61 -15
- data/test/vagrant/ssh_test.rb +166 -38
- data/test/vagrant/util/errors_test.rb +57 -0
- data/test/vagrant/util/progress_meter_test.rb +33 -0
- data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
- data/test/vagrant/util/template_renderer_test.rb +138 -0
- data/test/vagrant/vm_test.rb +3 -2
- data/vagrant.gemspec +88 -33
- metadata +94 -51
- data/bin/vagrant-box +0 -34
- data/bin/vagrant-down +0 -27
- data/bin/vagrant-halt +0 -28
- data/bin/vagrant-init +0 -27
- data/bin/vagrant-package +0 -29
- data/bin/vagrant-reload +0 -29
- data/bin/vagrant-resume +0 -27
- data/bin/vagrant-ssh +0 -27
- data/bin/vagrant-status +0 -29
- data/bin/vagrant-suspend +0 -27
- data/bin/vagrant-up +0 -29
- data/lib/vagrant/commands.rb +0 -234
- data/lib/vagrant/env.rb +0 -189
- data/lib/vagrant/stacked_proc_runner.rb +0 -33
- data/test/vagrant/commands_test.rb +0 -269
- data/test/vagrant/env_test.rb +0 -418
@@ -0,0 +1,259 @@
|
|
1
|
+
module Vagrant
|
2
|
+
# Represents a single Vagrant environment. This class is responsible
|
3
|
+
# for loading all of the Vagrantfile's for the given environment and
|
4
|
+
# storing references to the various instances.
|
5
|
+
class Environment
|
6
|
+
ROOTFILE_NAME = "Vagrantfile"
|
7
|
+
HOME_SUBDIRS = ["tmp", "boxes"]
|
8
|
+
|
9
|
+
include Util
|
10
|
+
|
11
|
+
attr_accessor :cwd
|
12
|
+
attr_reader :root_path
|
13
|
+
attr_reader :config
|
14
|
+
attr_reader :box
|
15
|
+
attr_accessor :vm
|
16
|
+
attr_reader :ssh
|
17
|
+
attr_reader :active_list
|
18
|
+
attr_reader :commands
|
19
|
+
|
20
|
+
#---------------------------------------------------------------
|
21
|
+
# Class Methods
|
22
|
+
#---------------------------------------------------------------
|
23
|
+
class <<self
|
24
|
+
# Loads and returns an environment given a specific working
|
25
|
+
# directory. If a working directory is not given, it will default
|
26
|
+
# to the pwd.
|
27
|
+
def load!(cwd=nil)
|
28
|
+
Environment.new(cwd).load!
|
29
|
+
end
|
30
|
+
|
31
|
+
# Verifies that VirtualBox is installed and that the version of
|
32
|
+
# VirtualBox installed is high enough. Also verifies that the
|
33
|
+
# configuration path is properly set.
|
34
|
+
def check_virtualbox!
|
35
|
+
version = VirtualBox.version
|
36
|
+
if version.nil?
|
37
|
+
error_and_exit(:virtualbox_not_detected)
|
38
|
+
elsif version.to_f < 3.1
|
39
|
+
error_and_exit(:virtualbox_invalid_version, :version => version.to_s)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(cwd=nil)
|
45
|
+
@cwd = cwd
|
46
|
+
end
|
47
|
+
|
48
|
+
#---------------------------------------------------------------
|
49
|
+
# Path Helpers
|
50
|
+
#---------------------------------------------------------------
|
51
|
+
|
52
|
+
# Specifies the "current working directory" for this environment.
|
53
|
+
# This is vital in determining the root path and therefore the
|
54
|
+
# dotfile, rootpath vagrantfile, etc. This defaults to the
|
55
|
+
# actual cwd (`Dir.pwd`).
|
56
|
+
def cwd
|
57
|
+
@cwd || Dir.pwd
|
58
|
+
end
|
59
|
+
|
60
|
+
# The path to the `dotfile`, which contains the persisted UUID of
|
61
|
+
# the VM if it exists.
|
62
|
+
def dotfile_path
|
63
|
+
File.join(root_path, config.vagrant.dotfile_name)
|
64
|
+
end
|
65
|
+
|
66
|
+
# The path to the home directory, which is usually in `~/.vagrant/~
|
67
|
+
def home_path
|
68
|
+
config ? config.vagrant.home : nil
|
69
|
+
end
|
70
|
+
|
71
|
+
# The path to the Vagrant tmp directory
|
72
|
+
def tmp_path
|
73
|
+
File.join(home_path, "tmp")
|
74
|
+
end
|
75
|
+
|
76
|
+
# The path to the Vagrant boxes directory
|
77
|
+
def boxes_path
|
78
|
+
File.join(home_path, "boxes")
|
79
|
+
end
|
80
|
+
|
81
|
+
#---------------------------------------------------------------
|
82
|
+
# Load Methods
|
83
|
+
#---------------------------------------------------------------
|
84
|
+
|
85
|
+
# Loads this entire environment, setting up the instance variables
|
86
|
+
# such as `vm`, `config`, etc. on this environment. The order this
|
87
|
+
# method calls its other methods is very particular.
|
88
|
+
def load!
|
89
|
+
load_root_path!
|
90
|
+
load_config!
|
91
|
+
load_home_directory!
|
92
|
+
load_box!
|
93
|
+
load_config!
|
94
|
+
self.class.check_virtualbox!
|
95
|
+
load_vm!
|
96
|
+
load_ssh!
|
97
|
+
load_active_list!
|
98
|
+
load_commands!
|
99
|
+
self
|
100
|
+
end
|
101
|
+
|
102
|
+
# Loads the root path of this environment, given the starting
|
103
|
+
# directory (the "cwd" of this environment for lack of better words).
|
104
|
+
# This method allows an environment in `/foo` to be detected from
|
105
|
+
# `/foo/bar` (similar to how git works in subdirectories)
|
106
|
+
def load_root_path!(path=nil)
|
107
|
+
path = Pathname.new(File.expand_path(path || cwd))
|
108
|
+
|
109
|
+
# Stop if we're at the root.
|
110
|
+
return false if path.root?
|
111
|
+
|
112
|
+
file = "#{path}/#{ROOTFILE_NAME}"
|
113
|
+
if File.exist?(file)
|
114
|
+
@root_path = path.to_s
|
115
|
+
return true
|
116
|
+
end
|
117
|
+
|
118
|
+
load_root_path!(path.parent)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Loads this environment's configuration and stores it in the {config}
|
122
|
+
# variable. The configuration loaded by this method is specified to
|
123
|
+
# this environment, meaning that it will use the given root directory
|
124
|
+
# to load the Vagrantfile into that context.
|
125
|
+
def load_config!
|
126
|
+
# Prepare load paths for config files
|
127
|
+
load_paths = [File.join(PROJECT_ROOT, "config", "default.rb")]
|
128
|
+
load_paths << File.join(box.directory, ROOTFILE_NAME) if box
|
129
|
+
load_paths << File.join(home_path, ROOTFILE_NAME) if home_path
|
130
|
+
load_paths << File.join(root_path, ROOTFILE_NAME) if root_path
|
131
|
+
|
132
|
+
# Clear out the old data
|
133
|
+
Config.reset!(self)
|
134
|
+
|
135
|
+
# Load each of the config files in order
|
136
|
+
load_paths.each do |path|
|
137
|
+
if File.exist?(path)
|
138
|
+
logger.info "Loading config from #{path}..."
|
139
|
+
load path
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# Execute the configuration stack and store the result
|
144
|
+
@config = Config.execute!
|
145
|
+
end
|
146
|
+
|
147
|
+
# Loads the home directory path and creates the necessary subdirectories
|
148
|
+
# within the home directory if they're not already created.
|
149
|
+
def load_home_directory!
|
150
|
+
# Setup the array of necessary home directories
|
151
|
+
dirs = HOME_SUBDIRS.collect { |subdir| File.join(home_path, subdir) }
|
152
|
+
dirs.unshift(home_path)
|
153
|
+
|
154
|
+
# Go through each required directory, creating it if it doesn't exist
|
155
|
+
dirs.each do |dir|
|
156
|
+
next if File.directory?(dir)
|
157
|
+
|
158
|
+
logger.info "Creating home directory since it doesn't exist: #{dir}"
|
159
|
+
FileUtils.mkdir_p(dir)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# Loads the specified box for this environment.
|
164
|
+
def load_box!
|
165
|
+
return unless root_path
|
166
|
+
|
167
|
+
@box = Box.find(self, config.vm.box) if config.vm.box
|
168
|
+
end
|
169
|
+
|
170
|
+
# Loads the persisted VM (if it exists) for this environment.
|
171
|
+
def load_vm!
|
172
|
+
return if !root_path || !File.file?(dotfile_path)
|
173
|
+
|
174
|
+
File.open(dotfile_path) do |f|
|
175
|
+
@vm = Vagrant::VM.find(f.read)
|
176
|
+
@vm.env = self if @vm
|
177
|
+
end
|
178
|
+
rescue Errno::ENOENT
|
179
|
+
@vm = nil
|
180
|
+
end
|
181
|
+
|
182
|
+
# Loads/initializes the SSH object
|
183
|
+
def load_ssh!
|
184
|
+
@ssh = SSH.new(self)
|
185
|
+
end
|
186
|
+
|
187
|
+
# Loads the activelist for this environment
|
188
|
+
def load_active_list!
|
189
|
+
@active_list = ActiveList.new(self)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Loads the instance of {Command} for this environment. This allows
|
193
|
+
# users of the instance to run commands such as "up" "down" etc. in
|
194
|
+
# the context of this environment.
|
195
|
+
def load_commands!
|
196
|
+
@commands = Command.new(self)
|
197
|
+
end
|
198
|
+
|
199
|
+
#---------------------------------------------------------------
|
200
|
+
# Methods to manage VM
|
201
|
+
#---------------------------------------------------------------
|
202
|
+
|
203
|
+
# Sets the VM to a new VM. This is not too useful but is used
|
204
|
+
# in {Command.up}. This will very likely be refactored at a later
|
205
|
+
# time.
|
206
|
+
def create_vm
|
207
|
+
@vm = VM.new
|
208
|
+
@vm.env = self
|
209
|
+
@vm
|
210
|
+
end
|
211
|
+
|
212
|
+
# Persists this environment's VM to the dotfile so it can be
|
213
|
+
# re-loaded at a later time.
|
214
|
+
def persist_vm
|
215
|
+
# Save to the dotfile for this project
|
216
|
+
File.open(dotfile_path, 'w+') do |f|
|
217
|
+
f.write(vm.uuid)
|
218
|
+
end
|
219
|
+
|
220
|
+
# Also add to the global store
|
221
|
+
active_list.add(vm)
|
222
|
+
end
|
223
|
+
|
224
|
+
# Removes this environment's VM from the dotfile.
|
225
|
+
def depersist_vm
|
226
|
+
# Delete the dotfile if it exists
|
227
|
+
File.delete(dotfile_path) if File.exist?(dotfile_path)
|
228
|
+
|
229
|
+
# Remove from the global store
|
230
|
+
active_list.remove(vm)
|
231
|
+
end
|
232
|
+
|
233
|
+
#---------------------------------------------------------------
|
234
|
+
# Methods to check for properties and error
|
235
|
+
#---------------------------------------------------------------
|
236
|
+
|
237
|
+
def require_root_path
|
238
|
+
error_and_exit(:rootfile_not_found) if !root_path
|
239
|
+
end
|
240
|
+
|
241
|
+
def require_box
|
242
|
+
require_root_path
|
243
|
+
|
244
|
+
if !box
|
245
|
+
if !Vagrant.config.vm.box
|
246
|
+
error_and_exit(:box_not_specified)
|
247
|
+
else
|
248
|
+
error_and_exit(:box_specified_doesnt_exist, :box_name => Vagrant.config.vm.box)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def require_persisted_vm
|
254
|
+
require_root_path
|
255
|
+
|
256
|
+
error_and_exit(:environment_not_created) if !vm
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
@@ -7,6 +7,13 @@ module Vagrant
|
|
7
7
|
class Base
|
8
8
|
include Vagrant::Util
|
9
9
|
|
10
|
+
# The environment which this is being provisioned in
|
11
|
+
attr_reader :env
|
12
|
+
|
13
|
+
def initialize(env)
|
14
|
+
@env = env
|
15
|
+
end
|
16
|
+
|
10
17
|
# This is the method called to "prepare" the provisioner. This is called
|
11
18
|
# before any actions are run by the action runner (see {Vagrant::Actions::Runner}).
|
12
19
|
# This can be used to setup shared folders, forward ports, etc. Whatever is
|
@@ -11,20 +11,26 @@ module Vagrant
|
|
11
11
|
attr_accessor :validation_key_path
|
12
12
|
attr_accessor :validation_client_name
|
13
13
|
attr_accessor :client_key_path
|
14
|
+
attr_accessor :node_name
|
14
15
|
|
15
16
|
# Chef solo specific config
|
16
17
|
attr_accessor :cookbooks_path
|
18
|
+
attr_accessor :roles_path
|
17
19
|
|
18
20
|
# Shared config
|
19
21
|
attr_accessor :provisioning_path
|
22
|
+
attr_accessor :log_level
|
20
23
|
attr_accessor :json
|
21
24
|
|
22
25
|
def initialize
|
23
26
|
@validation_client_name = "chef-validator"
|
24
27
|
@client_key_path = "/etc/chef/client.pem"
|
28
|
+
@node_name = "client"
|
25
29
|
|
26
30
|
@cookbooks_path = "cookbooks"
|
31
|
+
@roles_path = []
|
27
32
|
@provisioning_path = "/tmp/vagrant-chef"
|
33
|
+
@log_level = :info
|
28
34
|
@json = {
|
29
35
|
:instance_role => "vagrant",
|
30
36
|
:run_list => ["recipe[vagrant_main]"]
|
@@ -66,24 +72,33 @@ module Vagrant
|
|
66
72
|
Config.configures :chef, ChefConfig
|
67
73
|
|
68
74
|
def prepare
|
69
|
-
raise Actions::ActionException.new(
|
75
|
+
raise Actions::ActionException.new(:chef_base_invalid_provisioner)
|
70
76
|
end
|
71
77
|
|
72
78
|
def chown_provisioning_folder
|
73
79
|
logger.info "Setting permissions on chef provisioning folder..."
|
74
|
-
|
75
|
-
ssh.exec!("sudo mkdir -p #{
|
76
|
-
ssh.exec!("sudo chown #{
|
80
|
+
env.ssh.execute do |ssh|
|
81
|
+
ssh.exec!("sudo mkdir -p #{env.config.chef.provisioning_path}")
|
82
|
+
ssh.exec!("sudo chown #{env.config.ssh.username} #{env.config.chef.provisioning_path}")
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
86
|
+
def setup_config(template, filename, template_vars)
|
87
|
+
config_file = TemplateRenderer.render(template, {
|
88
|
+
:log_level => env.config.chef.log_level.to_sym
|
89
|
+
}.merge(template_vars))
|
90
|
+
|
91
|
+
logger.info "Uploading chef configuration script..."
|
92
|
+
env.ssh.upload!(StringIO.new(config_file), File.join(env.config.chef.provisioning_path, filename))
|
93
|
+
end
|
94
|
+
|
80
95
|
def setup_json
|
81
96
|
logger.info "Generating chef JSON and uploading..."
|
82
97
|
|
83
98
|
# Set up initial configuration
|
84
99
|
data = {
|
85
|
-
:config =>
|
86
|
-
:directory =>
|
100
|
+
:config => env.config,
|
101
|
+
:directory => env.config.vm.project_directory,
|
87
102
|
}
|
88
103
|
|
89
104
|
# And wrap it under the "vagrant" namespace
|
@@ -91,12 +106,12 @@ module Vagrant
|
|
91
106
|
|
92
107
|
# Merge with the "extra data" which isn't put under the
|
93
108
|
# vagrant namespace by default
|
94
|
-
data.merge!(
|
109
|
+
data.merge!(env.config.chef.json)
|
95
110
|
|
96
111
|
json = data.to_json
|
97
112
|
|
98
|
-
|
113
|
+
env.ssh.upload!(StringIO.new(json), File.join(env.config.chef.provisioning_path, "dna.json"))
|
99
114
|
end
|
100
115
|
end
|
101
116
|
end
|
102
|
-
end
|
117
|
+
end
|
@@ -4,26 +4,14 @@ module Vagrant
|
|
4
4
|
# with a chef server.
|
5
5
|
class ChefServer < Chef
|
6
6
|
def prepare
|
7
|
-
if
|
8
|
-
raise Actions::ActionException.new(
|
9
|
-
|
10
|
-
|
11
|
-
VM with the chef server.
|
12
|
-
msg
|
13
|
-
elsif !File.file?(Vagrant.config.chef.validation_key_path)
|
14
|
-
raise Actions::ActionException.new(<<-msg)
|
15
|
-
The validation key set for `config.chef.validation_key_path` does not exist! This
|
16
|
-
file needs to exist so it can be uploaded to the virtual machine. It is
|
17
|
-
currently set to "#{Vagrant.config.chef.validation_key_path}"
|
18
|
-
msg
|
7
|
+
if env.config.chef.validation_key_path.nil?
|
8
|
+
raise Actions::ActionException.new(:chef_server_validation_key_required)
|
9
|
+
elsif !File.file?(validation_key_path)
|
10
|
+
raise Actions::ActionException.new(:chef_server_validation_key_doesnt_exist)
|
19
11
|
end
|
20
12
|
|
21
|
-
if
|
22
|
-
raise Actions::ActionException.new(
|
23
|
-
Chef server provisioning requires that the `config.chef.chef_server_url` be set to the
|
24
|
-
URL of your chef server. Examples include "http://12.12.12.12:4000" and
|
25
|
-
"http://myserver.com:4000" (the port of course can be different, but 4000 is the default)
|
26
|
-
msg
|
13
|
+
if env.config.chef.chef_server_url.nil?
|
14
|
+
raise Actions::ActionException.new(:chef_server_url_required)
|
27
15
|
end
|
28
16
|
end
|
29
17
|
|
@@ -32,51 +20,38 @@ msg
|
|
32
20
|
create_client_key_folder
|
33
21
|
upload_validation_key
|
34
22
|
setup_json
|
35
|
-
|
23
|
+
setup_server_config
|
36
24
|
run_chef_client
|
37
25
|
end
|
38
26
|
|
39
27
|
def create_client_key_folder
|
40
28
|
logger.info "Creating folder to hold client key..."
|
41
|
-
path = Pathname.new(
|
29
|
+
path = Pathname.new(env.config.chef.client_key_path)
|
42
30
|
|
43
|
-
|
31
|
+
env.ssh.execute do |ssh|
|
44
32
|
ssh.exec!("sudo mkdir -p #{path.dirname}")
|
45
33
|
end
|
46
34
|
end
|
47
35
|
|
48
36
|
def upload_validation_key
|
49
37
|
logger.info "Uploading chef client validation key..."
|
50
|
-
|
38
|
+
env.ssh.upload!(validation_key_path, guest_validation_key_path)
|
51
39
|
end
|
52
40
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
validation_key "#{guest_validation_key_path}"
|
62
|
-
client_key "#{Vagrant.config.chef.client_key_path}"
|
63
|
-
|
64
|
-
file_store_path "/srv/chef/file_store"
|
65
|
-
file_cache_path "/srv/chef/cache"
|
66
|
-
|
67
|
-
pid_file "/var/run/chef/chef-client.pid"
|
68
|
-
|
69
|
-
Mixlib::Log::Formatter.show_time = true
|
70
|
-
solo
|
71
|
-
|
72
|
-
logger.info "Uploading chef-client configuration script..."
|
73
|
-
SSH.upload!(StringIO.new(solo_file), File.join(Vagrant.config.chef.provisioning_path, "client.rb"))
|
41
|
+
def setup_server_config
|
42
|
+
setup_config("chef_server_client", "client.rb", {
|
43
|
+
:node_name => env.config.chef.node_name,
|
44
|
+
:chef_server_url => env.config.chef.chef_server_url,
|
45
|
+
:validation_client_name => env.config.chef.validation_client_name,
|
46
|
+
:validation_key => guest_validation_key_path,
|
47
|
+
:client_key => env.config.chef.client_key_path
|
48
|
+
})
|
74
49
|
end
|
75
50
|
|
76
51
|
def run_chef_client
|
77
52
|
logger.info "Running chef-client..."
|
78
|
-
|
79
|
-
ssh.exec!("cd #{
|
53
|
+
env.ssh.execute do |ssh|
|
54
|
+
ssh.exec!("cd #{env.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json") do |channel, data, stream|
|
80
55
|
# TODO: Very verbose. It would be easier to save the data and only show it during
|
81
56
|
# an error, or when verbosity level is set high
|
82
57
|
logger.info("#{stream}: #{data}")
|
@@ -85,12 +60,12 @@ solo
|
|
85
60
|
end
|
86
61
|
|
87
62
|
def validation_key_path
|
88
|
-
File.expand_path(
|
63
|
+
File.expand_path(env.config.chef.validation_key_path, env.root_path)
|
89
64
|
end
|
90
65
|
|
91
66
|
def guest_validation_key_path
|
92
|
-
File.join(
|
67
|
+
File.join(@env.config.chef.provisioning_path, "validation.pem")
|
93
68
|
end
|
94
69
|
end
|
95
70
|
end
|
96
|
-
end
|
71
|
+
end
|