Class: Vagrant::Provisioners::ChefSolo
- Inherits:
-
Chef
- Object
- Base
- Chef
- Vagrant::Provisioners::ChefSolo
show all
- Defined in:
- lib/vagrant/provisioners/chef_solo.rb
Overview
This class implements provisioning via chef-solo.
Defined Under Namespace
Classes: Config
Instance Attribute Summary
Attributes inherited from Base
#action_env, #config
Instance Method Summary
collapse
Methods inherited from Chef
#chown_provisioning_folder, #setup_config, #setup_json, #verify_binary
Methods inherited from Base
#env, #initialize, register, registered, #vm
Instance Method Details
#cookbook_path(i) ⇒ Object
122
123
124
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 122
def cookbook_path(i)
folder_path("cookbooks", i)
end
|
#cookbooks_path ⇒ Object
130
131
132
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 130
def cookbooks_path
folders_path(config.cookbooks_path, "cookbooks").to_json
end
|
#folder_path(*args) ⇒ Object
88
89
90
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 88
def folder_path(*args)
File.join(config.provisioning_path, args.join("-"))
end
|
#folders_path(folders, folder) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 92
def folders_path(folders, folder)
folders = [folders] if folders.is_a?(String) || folders.first.is_a?(Symbol)
result = []
folders.each_with_index do |path, i|
path = [:host, path] if !path.is_a?(Array)
type, path = path
result << folder_path(folder, i) if type == :host
result << folder_path(path) if type == :vm
end
result = result[0].to_s if result.length == 1
result
end
|
#host_cookbook_paths ⇒ Object
114
115
116
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 114
def host_cookbook_paths
host_folder_paths(config.cookbooks_path)
end
|
#host_folder_paths(paths) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 74
def host_folder_paths(paths)
paths = [paths] if paths.is_a?(String) || paths.first.is_a?(Symbol)
paths.inject([]) do |acc, path|
path = [:host, path] if !path.is_a?(Array)
type, path = path
acc << File.expand_path(path, env.root_path) if type == :host
acc
end
end
|
#host_role_paths ⇒ Object
118
119
120
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 118
def host_role_paths
host_folder_paths(config.roles_path)
end
|
#prepare ⇒ Object
27
28
29
30
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 27
def prepare
share_cookbook_folders
share_role_folders
end
|
#provision! ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 32
def provision!
verify_binary("chef-solo")
chown_provisioning_folder
setup_json
setup_solo_config
run_chef_solo
end
|
#role_path(i) ⇒ Object
126
127
128
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 126
def role_path(i)
folder_path("roles", i)
end
|
#roles_path ⇒ Object
134
135
136
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 134
def roles_path
folders_path(config.roles_path, "roles").to_json
end
|
#run_chef_solo ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 62
def run_chef_solo
commands = ["cd #{config.provisioning_path}", "chef-solo -c solo.rb -j dna.json"]
env.ui.info I18n.t("vagrant.provisioners.chef.running_solo")
vm.ssh.execute do |ssh|
ssh.sudo!(commands) do |channel, type, data|
ssh.check_exit_status(data, commands) if type == :exit_status
env.ui.info("#{data}: #{type}") if type != :exit_status
end
end
end
|
#setup_solo_config ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 52
def setup_solo_config
setup_config("chef_solo_solo", "solo.rb", {
:node_name => config.node_name,
:provisioning_path => config.provisioning_path,
:cookbooks_path => cookbooks_path,
:recipe_url => config.recipe_url,
:roles_path => roles_path,
})
end
|
#share_cookbook_folders ⇒ Object
40
41
42
43
44
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 40
def share_cookbook_folders
host_cookbook_paths.each_with_index do |cookbook, i|
env.config.vm.share_folder("v-csc-#{i}", cookbook_path(i), cookbook)
end
end
|
#share_role_folders ⇒ Object
46
47
48
49
50
|
# File 'lib/vagrant/provisioners/chef_solo.rb', line 46
def share_role_folders
host_role_paths.each_with_index do |role, i|
env.config.vm.share_folder("v-csr-#{i}", role_path(i), role)
end
end
|