Class: Vagrant::Provisioners::ChefServer
- Inherits:
-
Chef
- Object
- Base
- Chef
- Vagrant::Provisioners::ChefServer
show all
- Defined in:
- lib/vagrant/provisioners/chef_server.rb
Overview
This class implements provisioning via chef-client, allowing provisioning with a chef server.
Instance Method Summary
collapse
Methods inherited from Chef
#chown_provisioning_folder, #setup_json
Methods included from Util
#error_and_exit, included, #logger, #wrap_output
Instance Method Details
#create_client_key_folder ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/vagrant/provisioners/chef_server.rb', line 39
def create_client_key_folder
logger.info "Creating folder to hold client key..."
path = Pathname.new(Vagrant.config.chef.client_key_path)
SSH.execute do |ssh|
ssh.exec!("sudo mkdir -p #{path.dirname}")
end
end
|
#guest_validation_key_path ⇒ Object
91
92
93
|
# File 'lib/vagrant/provisioners/chef_server.rb', line 91
def guest_validation_key_path
File.join(Vagrant.config.chef.provisioning_path, "validation.pem")
end
|
#prepare ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/vagrant/provisioners/chef_server.rb', line 6
def prepare
if Vagrant.config.chef.validation_key_path.nil?
raise Actions::ActionException.new(<<-msg)
Chef server provisioning requires that the `config.chef.validation_key_path` configuration
be set to a path on your local machine of the validation key used to register the
VM with the chef server.
msg
elsif !File.file?(Vagrant.config.chef.validation_key_path)
raise Actions::ActionException.new(<<-msg)
The validation key set for `config.chef.validation_key_path` does not exist! This
file needs to exist so it can be uploaded to the virtual machine. It is
currently set to "#{Vagrant.config.chef.validation_key_path}"
msg
end
if Vagrant.config.chef.chef_server_url.nil?
raise Actions::ActionException.new(<<-msg)
Chef server provisioning requires that the `config.chef.chef_server_url` be set to the
URL of your chef server. Examples include "http://12.12.12.12:4000" and
"http://myserver.com:4000" (the port of course can be different, but 4000 is the default)
msg
end
end
|
#provision! ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/vagrant/provisioners/chef_server.rb', line 30
def provision!
chown_provisioning_folder
create_client_key_folder
upload_validation_key
setup_json
setup_config
run_chef_client
end
|
#run_chef_client ⇒ Object
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/vagrant/provisioners/chef_server.rb', line 76
def run_chef_client
logger.info "Running chef-client..."
SSH.execute do |ssh|
ssh.exec!("cd #{Vagrant.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json") do |channel, data, stream|
logger.info("#{stream}: #{data}")
end
end
end
|
#setup_config ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/vagrant/provisioners/chef_server.rb', line 53
def setup_config
solo_file = <<-solo
log_level :info
log_location STDOUT
ssl_verify_mode :verify_none
chef_server_url "#{Vagrant.config.chef.chef_server_url}"
validation_client_name "#{Vagrant.config.chef.validation_client_name}"
validation_key "#{guest_validation_key_path}"
client_key "#{Vagrant.config.chef.client_key_path}"
file_store_path "/srv/chef/file_store"
file_cache_path "/srv/chef/cache"
pid_file "/var/run/chef/chef-client.pid"
Mixlib::Log::Formatter.show_time = true
solo
logger.info "Uploading chef-client configuration script..."
SSH.upload!(StringIO.new(solo_file), File.join(Vagrant.config.chef.provisioning_path, "client.rb"))
end
|
#upload_validation_key ⇒ Object
48
49
50
51
|
# File 'lib/vagrant/provisioners/chef_server.rb', line 48
def upload_validation_key
logger.info "Uploading chef client validation key..."
SSH.upload!(validation_key_path, guest_validation_key_path)
end
|
#validation_key_path ⇒ Object
87
88
89
|
# File 'lib/vagrant/provisioners/chef_server.rb', line 87
def validation_key_path
File.expand_path(Vagrant.config.chef.validation_key_path, Env.root_path)
end
|