chef-solo-wrapper 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/cs +28 -13
- data/lib/config_helper.rb +23 -5
- metadata +3 -3
data/bin/cs
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
# See the License for the specific language governing permissions and
|
17
17
|
# limitations under the License.
|
18
18
|
|
19
|
-
CHEF_SOLO_WRAPPER_VERSION = '0.0.
|
19
|
+
CHEF_SOLO_WRAPPER_VERSION = '0.0.7'
|
20
20
|
COOKBOOKS_SRC_DEST = '/usr/src/chef-cookbooks'
|
21
21
|
|
22
22
|
require 'rubygems'
|
@@ -103,6 +103,8 @@ if opts[:setup]
|
|
103
103
|
config.install_rest_connection
|
104
104
|
when 'config'
|
105
105
|
config.setup_solo_rb(solo_file)
|
106
|
+
when 'config-sandbox'
|
107
|
+
config.setup_solo_rb_sandbox(solo_file)
|
106
108
|
when 'node'
|
107
109
|
config.setup_node_json(json_file)
|
108
110
|
when 'all'
|
@@ -130,14 +132,15 @@ config.pre_checks
|
|
130
132
|
|
131
133
|
# get json if available
|
132
134
|
if opts[:json]
|
133
|
-
|
135
|
+
puts " DEBUG: Using #{opts[:json]}."
|
136
|
+
attributes = File.new(opts[:json], "r").read
|
134
137
|
else
|
135
|
-
if File.file?(
|
136
|
-
node_file =
|
137
|
-
attributes = JSON.parse(File.new(
|
138
|
+
if File.file?(json_file)
|
139
|
+
node_file = json_file
|
140
|
+
attributes = JSON.parse(File.new(json_file, "r").read)
|
138
141
|
elsif File.file?("#{File.expand_path('~')}/node.json")
|
139
142
|
node_file = "#{File.expand_path('~')}/node.json"
|
140
|
-
attributes = JSON.parse(File.new(
|
143
|
+
attributes = JSON.parse(File.new(node_file, "r").read)
|
141
144
|
else
|
142
145
|
node_file = "#{File.expand_path('~')}/node.json"
|
143
146
|
attributes = JSON.parse("{\n}\n")
|
@@ -191,25 +194,29 @@ if opts[:server]
|
|
191
194
|
end
|
192
195
|
end
|
193
196
|
}
|
194
|
-
puts " DEBUG:\n#{p server_attributes}"
|
197
|
+
puts " DEBUG:\n#{p server_attributes}" if opts[:debug]
|
195
198
|
end
|
196
199
|
|
197
200
|
# merge attributes
|
198
201
|
if server_attributes
|
199
202
|
puts server_attributes.to_json
|
200
|
-
puts ' DEBUG: Merging attributes.'
|
203
|
+
puts ' DEBUG: Merging attributes.' if opts[:debug]
|
201
204
|
attributes = server_attributes.merge(attributes)
|
202
205
|
else
|
203
|
-
puts ' DEBUG: No server attributes to merge.'
|
206
|
+
puts ' DEBUG: No server attributes to merge.' if opts[:debug]
|
204
207
|
end
|
205
208
|
|
206
209
|
# override runlist
|
207
210
|
if opts[:run]
|
211
|
+
puts " Overriding run_list with: #{opts[:run]}" if opts[:verbose]
|
208
212
|
attributes['run_list'] = "#{opts[:run]}"
|
209
213
|
end
|
210
214
|
|
215
|
+
# new attributes
|
216
|
+
puts " DEBUG: Final attributes: #{attributes.to_json}" if opts[:debug]
|
217
|
+
|
211
218
|
# write attributes back to local node.json
|
212
|
-
if opts[:write] and
|
219
|
+
if opts[:write] and attributes
|
213
220
|
node_json = JSON.pretty_generate(attributes)
|
214
221
|
puts " DEBUG: Node Attributes: \n #{node_json}" if opts[:debug]
|
215
222
|
puts " DEBUG: Writing attributes to #{json_file}" if opts[:debug]
|
@@ -221,6 +228,9 @@ if opts[:write] and server_attributes
|
|
221
228
|
end
|
222
229
|
end
|
223
230
|
|
231
|
+
# debug for final node.json
|
232
|
+
puts "== node.json ==\n#{File.open(json_file, "r").read}\n==" if ( opts[:debug] or opts[:verbose] )
|
233
|
+
|
224
234
|
# pre append options
|
225
235
|
chef_config = " -c #{opts[:config]}" if opts[:config]
|
226
236
|
chef_json = " -j #{opts[:json]}" if opts[:json]
|
@@ -234,8 +244,7 @@ else
|
|
234
244
|
end
|
235
245
|
|
236
246
|
# build chef solo command
|
237
|
-
cmd = "#{cs}#{chef_config}#{chef_json} --log_level #{opts.loglevel}
|
238
|
-
puts " DEBUG: running #{cmd}" if opts[:debug]
|
247
|
+
cmd = "#{cs}#{chef_config}#{chef_json} --log_level #{opts.loglevel}"
|
239
248
|
|
240
249
|
# import chef
|
241
250
|
puts 'Importing Chef RubyGem.' if opts[:verbose]
|
@@ -250,7 +259,13 @@ end
|
|
250
259
|
# finally, run chef-solo
|
251
260
|
puts 'Starting Chef Solo.' unless !(opts[:verbose] || opts[:debug])
|
252
261
|
unless opts[:dry]
|
253
|
-
|
262
|
+
begin
|
263
|
+
puts " DEBUG: running #{cmd}" if opts[:debug]
|
264
|
+
system(cmd)
|
265
|
+
rescue
|
266
|
+
puts 'Chef run failed!'
|
267
|
+
exit 1
|
268
|
+
end
|
254
269
|
else
|
255
270
|
puts 'Dry run only, exiting.'
|
256
271
|
exit
|
data/lib/config_helper.rb
CHANGED
@@ -30,9 +30,15 @@ class ConfigHelper
|
|
30
30
|
def install_chef
|
31
31
|
puts
|
32
32
|
puts '=> Setting up Chef Solo.'
|
33
|
-
|
33
|
+
lsb_release = system("`which lsb_release`")
|
34
|
+
if ! lsb_release
|
35
|
+
puts ' DEBUG: lsb_release not found.' if @debug
|
36
|
+
lsb_release = 'none'
|
37
|
+
end
|
38
|
+
case "#{lsb_release.strip}"
|
34
39
|
when 'Ubuntu'
|
35
40
|
puts 'Ubuntu detected; installing from opscode apt.'
|
41
|
+
( puts 'Chef already installed, skipping.' and return ) if system("dpkg -l | grep chef")
|
36
42
|
system("DEBIAN_FRONTEND=noninteractive")
|
37
43
|
system("sudo mkdir -p /etc/apt/trusted.gpg.d")
|
38
44
|
system("gpg --keyserver keys.gnupg.net --recv-keys 83EF826A")
|
@@ -56,6 +62,19 @@ class ConfigHelper
|
|
56
62
|
end
|
57
63
|
end
|
58
64
|
end
|
65
|
+
|
66
|
+
def setup_solo_rb_sandbox(file, sandbox_version=5.8)
|
67
|
+
raise "RightScale cookbooks cache, /var/cache/rightscale/cookbooks not found!" unless File.exists?('/var/cache/rightscale/cookbooks')
|
68
|
+
puts "=> Setting up #{file}."
|
69
|
+
if sandbox_version.to_s == '5.8'
|
70
|
+
cookbooks_cache = '/var/cache/rightscale/cookbooks/default'
|
71
|
+
else
|
72
|
+
cookbooks_cache = '/var/cache/rightscale/cookbooks'
|
73
|
+
end
|
74
|
+
system('mkdir -p /etc/chef')
|
75
|
+
cookbooks_path = Dir.glob("#{cookbooks_cache}/*").map {|element| "\"#{element}\"" }.join(', ')
|
76
|
+
File.open(file, "w") {|f| f.write 'file_cache_path "/var/chef-solo"'+"\n"+'cookbook_path [ "'+"#{cookbooks_path}"+'" ]'+"\n"'json_attribs "/etc/chef/node.json"'+"\n"}
|
77
|
+
end
|
59
78
|
|
60
79
|
def setup_solo_rb(file, auto=@setup_defaults)
|
61
80
|
puts "=> Setting up #{file}."
|
@@ -145,19 +164,18 @@ class ConfigHelper
|
|
145
164
|
end
|
146
165
|
if File.file?("#{ENV['HOME']}/solo.rb")
|
147
166
|
solo = "#{ENV['HOME']}/solo.rb"
|
148
|
-
|
149
|
-
puts ' DEBUG: ~/solo.rb: not found.' if @debug
|
167
|
+
puts " DEBUG: Using #{ENV['HOME']}/solo.rb as preferred." if @debug
|
150
168
|
end
|
151
169
|
unless solo
|
152
170
|
puts 'FATAL: No solo.rb file found (see http://wiki.opscode.com/display/chef/Chef+Solo), exiting.'
|
153
171
|
exit 1
|
154
172
|
else
|
155
|
-
puts "
|
173
|
+
puts " DEBUG: Using #{solo}." if @debug
|
156
174
|
if File.zero?(solo) then
|
157
175
|
puts "FATAL: #{solo} is empty, exiting."
|
158
176
|
exit 1
|
159
177
|
end
|
160
|
-
puts File.new(solo, 'r').read if @debug
|
178
|
+
puts "== solo.rb ==\n#{File.new(solo, 'r').read.strip}\n==" if @debug
|
161
179
|
end
|
162
180
|
end
|
163
181
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-solo-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Fordham
|