ridley 0.12.4 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/lib/ridley.rb +3 -3
- data/lib/ridley/bootstrap_context.rb +100 -0
- data/lib/ridley/bootstrap_context/unix.rb +74 -0
- data/lib/ridley/bootstrap_context/windows.rb +120 -0
- data/lib/ridley/chef_objects/node_object.rb +8 -5
- data/lib/ridley/host_commander.rb +207 -0
- data/lib/ridley/host_connector.rb +49 -87
- data/lib/ridley/host_connector/ssh.rb +153 -39
- data/lib/ridley/host_connector/winrm.rb +164 -39
- data/lib/ridley/resources/node_resource.rb +52 -56
- data/lib/ridley/version.rb +1 -1
- data/ridley.gemspec +0 -2
- data/spec/spec_helper.rb +4 -4
- data/spec/support/chef_server.rb +9 -3
- data/spec/unit/ridley/{bootstrap_bindings/unix_template_binding_spec.rb → bootstrap_context/unix_spec.rb} +2 -2
- data/spec/unit/ridley/{bootstrap_bindings/windows_template_binding_spec.rb → bootstrap_context/windows_spec.rb} +2 -2
- data/spec/unit/ridley/{mixin/bootstrap_binding_spec.rb → bootstrap_context_spec.rb} +2 -6
- data/spec/unit/ridley/host_commander_spec.rb +208 -0
- data/spec/unit/ridley/host_connector/ssh_spec.rb +37 -31
- data/spec/unit/ridley/host_connector/winrm_spec.rb +124 -31
- data/spec/unit/ridley/host_connector_spec.rb +23 -147
- data/spec/unit/ridley/resources/node_resource_spec.rb +55 -115
- metadata +17 -66
- data/lib/ridley/bootstrap_bindings.rb +0 -3
- data/lib/ridley/bootstrap_bindings/unix_template_binding.rb +0 -108
- data/lib/ridley/bootstrap_bindings/windows_template_binding.rb +0 -163
- data/lib/ridley/bootstrapper.rb +0 -89
- data/lib/ridley/bootstrapper/context.rb +0 -81
- data/lib/ridley/host_connector/response_set.rb +0 -98
- data/lib/ridley/host_connector/ssh/worker.rb +0 -135
- data/lib/ridley/host_connector/winrm/worker.rb +0 -159
- data/lib/ridley/log.rb +0 -10
- data/lib/ridley/mixin/bootstrap_binding.rb +0 -77
- data/spec/unit/ridley/bootstrapper/context_spec.rb +0 -45
- data/spec/unit/ridley/bootstrapper_spec.rb +0 -96
- data/spec/unit/ridley/host_connector/response_set_spec.rb +0 -112
- data/spec/unit/ridley/host_connector/ssh/worker_spec.rb +0 -57
- data/spec/unit/ridley/host_connector/winrm/worker_spec.rb +0 -139
@@ -3,163 +3,103 @@ require 'spec_helper'
|
|
3
3
|
describe Ridley::NodeResource do
|
4
4
|
let(:host) { "33.33.33.10" }
|
5
5
|
let(:worker) { double('worker', alive?: true, terminate: nil) }
|
6
|
+
let(:host_commander) { double('host-commander') }
|
6
7
|
let(:options) do
|
7
8
|
{
|
8
|
-
server_url:
|
9
|
-
validator_path:
|
10
|
-
validator_client:
|
11
|
-
encrypted_data_bag_secret:
|
12
|
-
ssh:
|
13
|
-
|
14
|
-
|
15
|
-
},
|
16
|
-
winrm: {
|
17
|
-
user: "Administrator",
|
18
|
-
password: "secret"
|
19
|
-
},
|
20
|
-
chef_version: "11.4.0"
|
9
|
+
server_url: double('server_url'),
|
10
|
+
validator_path: double('validator_path'),
|
11
|
+
validator_client: double('validator_client'),
|
12
|
+
encrypted_data_bag_secret: double('encrypted_data_bag_secret'),
|
13
|
+
ssh: double('ssh'),
|
14
|
+
winrm: double('winrm'),
|
15
|
+
chef_version: double('chef_version')
|
21
16
|
}
|
22
17
|
end
|
23
|
-
let(:instance)
|
18
|
+
let(:instance) do
|
19
|
+
inst = described_class.new(double, options)
|
20
|
+
inst.stub(connection: chef_zero_connection, host_commander: host_commander)
|
21
|
+
inst
|
22
|
+
end
|
24
23
|
|
25
24
|
describe "#bootstrap" do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
validator_path: fixtures_path.join("reset.pem").to_s,
|
30
|
-
encrypted_data_bag_secret: File.read(fixtures_path.join("reset.pem"))
|
31
|
-
}
|
25
|
+
it "sends the message #bootstrap to the instance's host_commander" do
|
26
|
+
host_commander.should_receive(:bootstrap).with(host, options)
|
27
|
+
instance.bootstrap(host)
|
32
28
|
end
|
33
|
-
let(:bootstrapper) { double('bootstrapper', run: nil) }
|
34
|
-
subject { instance }
|
35
|
-
before { Ridley::Bootstrapper.should_receive(:new).with(hosts, anything).and_return(bootstrapper) }
|
36
|
-
|
37
|
-
it "runs the Bootstrapper" do
|
38
|
-
bootstrapper.should_receive(:run)
|
39
29
|
|
40
|
-
|
30
|
+
it "passes pre-configured options to #bootstrap" do
|
31
|
+
host_commander.should_receive(:bootstrap).with(host, options)
|
32
|
+
instance.bootstrap(host)
|
41
33
|
end
|
42
34
|
end
|
43
35
|
|
44
36
|
describe "#chef_run" do
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
before do
|
50
|
-
Ridley::HostConnector.stub(:new).and_return(worker)
|
51
|
-
worker.stub(:chef_client).and_return(response)
|
52
|
-
end
|
53
|
-
|
54
|
-
it { should eql(response) }
|
55
|
-
|
56
|
-
context "when it executes unsuccessfully" do
|
57
|
-
let(:response) { [ :error, double('response', stderr: 'failure_message') ] }
|
58
|
-
|
59
|
-
it { should eql(response) }
|
60
|
-
end
|
61
|
-
|
62
|
-
it "terminates the worker" do
|
63
|
-
worker.should_receive(:terminate)
|
64
|
-
chef_run
|
37
|
+
it "sends the message #chef_client to the instance's host_commander" do
|
38
|
+
host_commander.should_receive(:chef_client).with(host, ssh: instance.ssh, winrm: instance.winrm)
|
39
|
+
instance.chef_run(host)
|
65
40
|
end
|
66
41
|
end
|
67
42
|
|
68
43
|
describe "#put_secret" do
|
69
|
-
let(:
|
70
|
-
let(:response) { [ :ok, double('response', stdout: 'success_message') ] }
|
71
|
-
subject { put_secret }
|
72
|
-
|
73
|
-
before do
|
74
|
-
Ridley::HostConnector.stub(:new).and_return(worker)
|
75
|
-
worker.stub(:put_secret).and_return(response)
|
76
|
-
end
|
77
|
-
|
78
|
-
it { should eql(response) }
|
79
|
-
|
80
|
-
context "when it executes unsuccessfully" do
|
81
|
-
let(:response) { [ :error, double('response', stderr: 'failure_message') ] }
|
82
|
-
|
83
|
-
it { should eql(response) }
|
84
|
-
end
|
44
|
+
let(:secret) { options[:encrypted_data_bag_secret] }
|
85
45
|
|
86
|
-
it "
|
87
|
-
|
88
|
-
put_secret
|
46
|
+
it "sends the message #put_secret to the instance's host_commander" do
|
47
|
+
host_commander.should_receive(:put_secret).with(host, secret, options.slice(:ssh, :winrm))
|
48
|
+
instance.put_secret(host)
|
89
49
|
end
|
90
50
|
end
|
91
51
|
|
92
52
|
describe "#ruby_script" do
|
93
|
-
let(:ruby_script) { instance.ruby_script(host, command_lines) }
|
94
|
-
let(:response) { [:ok, double('response', stdout: 'success_message')] }
|
95
53
|
let(:command_lines) { ["puts 'hello'", "puts 'there'"] }
|
96
|
-
subject { ruby_script }
|
97
54
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
it { should eq(response) }
|
104
|
-
|
105
|
-
context "when it executes unsuccessfully" do
|
106
|
-
let(:response) { [:error, double('response', stderr: 'failure_message')] }
|
107
|
-
|
108
|
-
it { should eq(response) }
|
109
|
-
end
|
110
|
-
|
111
|
-
it "terminates the worker" do
|
112
|
-
worker.should_receive(:terminate)
|
113
|
-
ruby_script
|
55
|
+
it "sends the message #ruby_script to the instance's host_commander" do
|
56
|
+
host_commander.should_receive(:ruby_script).with(host, command_lines, ssh: instance.ssh, winrm: instance.winrm)
|
57
|
+
instance.ruby_script(host, command_lines)
|
114
58
|
end
|
115
59
|
end
|
116
60
|
|
117
61
|
describe "#execute_command" do
|
118
|
-
let(:execute_command) { instance.execute_command(host, command) }
|
119
|
-
let(:response) { [:ok, double('response', stdout: 'success_message')] }
|
120
62
|
let(:command) { "echo 'hello world'" }
|
121
|
-
subject { execute_command }
|
122
|
-
|
123
|
-
before do
|
124
|
-
Ridley::HostConnector.stub(:new).and_return(worker)
|
125
|
-
worker.stub(:run).and_return(response)
|
126
|
-
end
|
127
|
-
|
128
|
-
it { should eq(response) }
|
129
63
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
it { should eq(response) }
|
64
|
+
it "sends the message #run to the instance's host_commander" do
|
65
|
+
host_commander.should_receive(:run).with(host, command, ssh: instance.ssh, winrm: instance.winrm)
|
66
|
+
instance.execute_command(host, command)
|
134
67
|
end
|
135
68
|
end
|
136
69
|
|
137
70
|
describe "#merge_data" do
|
138
|
-
|
139
|
-
let(:
|
140
|
-
let(:
|
141
|
-
|
142
|
-
|
71
|
+
let(:node_name) { "rspec-test" }
|
72
|
+
let(:run_list) { [ "recipe[one]", "recipe[two]" ] }
|
73
|
+
let(:attributes) { { deep: { two: "val" } } }
|
74
|
+
|
75
|
+
subject(:result) { instance.merge_data(node_name, run_list: run_list, attributes: attributes) }
|
76
|
+
|
77
|
+
context "when a node of the given name exists" do
|
78
|
+
before do
|
79
|
+
chef_node(node_name,
|
80
|
+
run_list: [ "recipe[one]", "recipe[three]" ],
|
81
|
+
normal: { deep: { one: "val" } }
|
82
|
+
)
|
83
|
+
end
|
143
84
|
|
144
|
-
|
145
|
-
|
85
|
+
it "returns a Ridley::NodeObject" do
|
86
|
+
expect(result).to be_a(Ridley::NodeObject)
|
87
|
+
end
|
146
88
|
|
147
|
-
it "
|
148
|
-
|
149
|
-
|
150
|
-
subject.should_receive(:update).with(updated)
|
89
|
+
it "has a union between the run list of the original node and the new run list" do
|
90
|
+
expect(result.run_list).to eql(["recipe[one]","recipe[three]","recipe[two]"])
|
91
|
+
end
|
151
92
|
|
152
|
-
|
93
|
+
it "has a deep merge between the attributes of the original node and the new attributes" do
|
94
|
+
expect(result.normal.to_hash).to eql(deep: { one: "val", two: "val" })
|
153
95
|
end
|
154
96
|
end
|
155
97
|
|
156
98
|
context "when a node with the given name does not exist" do
|
157
|
-
|
99
|
+
let(:node_name) { "does_not_exist" }
|
158
100
|
|
159
101
|
it "raises a ResourceNotFound error" do
|
160
|
-
expect {
|
161
|
-
subject.merge_data(node, data)
|
162
|
-
}.to raise_error(Ridley::Errors::ResourceNotFound)
|
102
|
+
expect { result }.to raise_error(Ridley::Errors::ResourceNotFound)
|
163
103
|
end
|
164
104
|
end
|
165
105
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0.rc1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jamie Winsor
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -107,22 +107,6 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: 2.0.2
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: mixlib-log
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ! '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 1.3.0
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ! '>='
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: 1.3.0
|
126
110
|
- !ruby/object:Gem::Dependency
|
127
111
|
name: mixlib-shellout
|
128
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,22 +123,6 @@ dependencies:
|
|
139
123
|
- - ! '>='
|
140
124
|
- !ruby/object:Gem::Version
|
141
125
|
version: 1.1.0
|
142
|
-
- !ruby/object:Gem::Dependency
|
143
|
-
name: mixlib-config
|
144
|
-
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
|
-
requirements:
|
147
|
-
- - ! '>='
|
148
|
-
- !ruby/object:Gem::Version
|
149
|
-
version: 1.1.0
|
150
|
-
type: :runtime
|
151
|
-
prerelease: false
|
152
|
-
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
|
-
requirements:
|
155
|
-
- - ! '>='
|
156
|
-
- !ruby/object:Gem::Version
|
157
|
-
version: 1.1.0
|
158
126
|
- !ruby/object:Gem::Dependency
|
159
127
|
name: mixlib-authentication
|
160
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -269,11 +237,9 @@ files:
|
|
269
237
|
- bootstrappers/unix_omnibus.erb
|
270
238
|
- bootstrappers/windows_omnibus.erb
|
271
239
|
- lib/ridley.rb
|
272
|
-
- lib/ridley/
|
273
|
-
- lib/ridley/
|
274
|
-
- lib/ridley/
|
275
|
-
- lib/ridley/bootstrapper.rb
|
276
|
-
- lib/ridley/bootstrapper/context.rb
|
240
|
+
- lib/ridley/bootstrap_context.rb
|
241
|
+
- lib/ridley/bootstrap_context/unix.rb
|
242
|
+
- lib/ridley/bootstrap_context/windows.rb
|
277
243
|
- lib/ridley/chef.rb
|
278
244
|
- lib/ridley/chef/chefignore.rb
|
279
245
|
- lib/ridley/chef/cookbook.rb
|
@@ -293,15 +259,12 @@ files:
|
|
293
259
|
- lib/ridley/client.rb
|
294
260
|
- lib/ridley/connection.rb
|
295
261
|
- lib/ridley/errors.rb
|
262
|
+
- lib/ridley/host_commander.rb
|
296
263
|
- lib/ridley/host_connector.rb
|
297
264
|
- lib/ridley/host_connector/response.rb
|
298
|
-
- lib/ridley/host_connector/response_set.rb
|
299
265
|
- lib/ridley/host_connector/ssh.rb
|
300
|
-
- lib/ridley/host_connector/ssh/worker.rb
|
301
266
|
- lib/ridley/host_connector/winrm.rb
|
302
267
|
- lib/ridley/host_connector/winrm/command_uploader.rb
|
303
|
-
- lib/ridley/host_connector/winrm/worker.rb
|
304
|
-
- lib/ridley/log.rb
|
305
268
|
- lib/ridley/logging.rb
|
306
269
|
- lib/ridley/middleware.rb
|
307
270
|
- lib/ridley/middleware/chef_auth.rb
|
@@ -311,7 +274,6 @@ files:
|
|
311
274
|
- lib/ridley/middleware/parse_json.rb
|
312
275
|
- lib/ridley/middleware/retry.rb
|
313
276
|
- lib/ridley/mixin.rb
|
314
|
-
- lib/ridley/mixin/bootstrap_binding.rb
|
315
277
|
- lib/ridley/mixin/checksum.rb
|
316
278
|
- lib/ridley/mixin/shell_out.rb
|
317
279
|
- lib/ridley/resource.rb
|
@@ -361,10 +323,9 @@ files:
|
|
361
323
|
- spec/support/filepath_matchers.rb
|
362
324
|
- spec/support/shared_examples/ridley_resource.rb
|
363
325
|
- spec/support/spec_helpers.rb
|
364
|
-
- spec/unit/ridley/
|
365
|
-
- spec/unit/ridley/
|
366
|
-
- spec/unit/ridley/
|
367
|
-
- spec/unit/ridley/bootstrapper_spec.rb
|
326
|
+
- spec/unit/ridley/bootstrap_context/unix_spec.rb
|
327
|
+
- spec/unit/ridley/bootstrap_context/windows_spec.rb
|
328
|
+
- spec/unit/ridley/bootstrap_context_spec.rb
|
368
329
|
- spec/unit/ridley/chef/chefignore_spec.rb
|
369
330
|
- spec/unit/ridley/chef/cookbook_spec.rb
|
370
331
|
- spec/unit/ridley/chef/digester_spec.rb
|
@@ -380,18 +341,15 @@ files:
|
|
380
341
|
- spec/unit/ridley/client_spec.rb
|
381
342
|
- spec/unit/ridley/connection_spec.rb
|
382
343
|
- spec/unit/ridley/errors_spec.rb
|
383
|
-
- spec/unit/ridley/
|
384
|
-
- spec/unit/ridley/host_connector/ssh/worker_spec.rb
|
344
|
+
- spec/unit/ridley/host_commander_spec.rb
|
385
345
|
- spec/unit/ridley/host_connector/ssh_spec.rb
|
386
346
|
- spec/unit/ridley/host_connector/winrm/command_uploader_spec.rb
|
387
|
-
- spec/unit/ridley/host_connector/winrm/worker_spec.rb
|
388
347
|
- spec/unit/ridley/host_connector/winrm_spec.rb
|
389
348
|
- spec/unit/ridley/host_connector_spec.rb
|
390
349
|
- spec/unit/ridley/middleware/chef_auth_spec.rb
|
391
350
|
- spec/unit/ridley/middleware/chef_response_spec.rb
|
392
351
|
- spec/unit/ridley/middleware/gzip_spec.rb
|
393
352
|
- spec/unit/ridley/middleware/parse_json_spec.rb
|
394
|
-
- spec/unit/ridley/mixin/bootstrap_binding_spec.rb
|
395
353
|
- spec/unit/ridley/resource_spec.rb
|
396
354
|
- spec/unit/ridley/resources/client_resource_spec.rb
|
397
355
|
- spec/unit/ridley/resources/cookbook_resource_spec.rb
|
@@ -420,12 +378,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
420
378
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
421
379
|
none: false
|
422
380
|
requirements:
|
423
|
-
- - ! '
|
381
|
+
- - ! '>'
|
424
382
|
- !ruby/object:Gem::Version
|
425
|
-
version:
|
426
|
-
segments:
|
427
|
-
- 0
|
428
|
-
hash: 744717169722095875
|
383
|
+
version: 1.3.1
|
429
384
|
requirements: []
|
430
385
|
rubyforge_project:
|
431
386
|
rubygems_version: 1.8.23
|
@@ -466,10 +421,9 @@ test_files:
|
|
466
421
|
- spec/support/filepath_matchers.rb
|
467
422
|
- spec/support/shared_examples/ridley_resource.rb
|
468
423
|
- spec/support/spec_helpers.rb
|
469
|
-
- spec/unit/ridley/
|
470
|
-
- spec/unit/ridley/
|
471
|
-
- spec/unit/ridley/
|
472
|
-
- spec/unit/ridley/bootstrapper_spec.rb
|
424
|
+
- spec/unit/ridley/bootstrap_context/unix_spec.rb
|
425
|
+
- spec/unit/ridley/bootstrap_context/windows_spec.rb
|
426
|
+
- spec/unit/ridley/bootstrap_context_spec.rb
|
473
427
|
- spec/unit/ridley/chef/chefignore_spec.rb
|
474
428
|
- spec/unit/ridley/chef/cookbook_spec.rb
|
475
429
|
- spec/unit/ridley/chef/digester_spec.rb
|
@@ -485,18 +439,15 @@ test_files:
|
|
485
439
|
- spec/unit/ridley/client_spec.rb
|
486
440
|
- spec/unit/ridley/connection_spec.rb
|
487
441
|
- spec/unit/ridley/errors_spec.rb
|
488
|
-
- spec/unit/ridley/
|
489
|
-
- spec/unit/ridley/host_connector/ssh/worker_spec.rb
|
442
|
+
- spec/unit/ridley/host_commander_spec.rb
|
490
443
|
- spec/unit/ridley/host_connector/ssh_spec.rb
|
491
444
|
- spec/unit/ridley/host_connector/winrm/command_uploader_spec.rb
|
492
|
-
- spec/unit/ridley/host_connector/winrm/worker_spec.rb
|
493
445
|
- spec/unit/ridley/host_connector/winrm_spec.rb
|
494
446
|
- spec/unit/ridley/host_connector_spec.rb
|
495
447
|
- spec/unit/ridley/middleware/chef_auth_spec.rb
|
496
448
|
- spec/unit/ridley/middleware/chef_response_spec.rb
|
497
449
|
- spec/unit/ridley/middleware/gzip_spec.rb
|
498
450
|
- spec/unit/ridley/middleware/parse_json_spec.rb
|
499
|
-
- spec/unit/ridley/mixin/bootstrap_binding_spec.rb
|
500
451
|
- spec/unit/ridley/resource_spec.rb
|
501
452
|
- spec/unit/ridley/resources/client_resource_spec.rb
|
502
453
|
- spec/unit/ridley/resources/cookbook_resource_spec.rb
|
@@ -1,108 +0,0 @@
|
|
1
|
-
module Ridley
|
2
|
-
# Represents a binding that will be evaluated as an ERB template. When bootstrapping
|
3
|
-
# nodes, an instance of this class represents the customizable and necessary configurations
|
4
|
-
# needed by the Host in order to install and connect to Chef. By default, this class will be used
|
5
|
-
# when SSH is the best way to connect to the node.
|
6
|
-
#
|
7
|
-
# @author Kyle Allan <kallan@riotgames.com>
|
8
|
-
class UnixTemplateBinding
|
9
|
-
include Ridley::BootstrapBinding
|
10
|
-
|
11
|
-
attr_reader :sudo
|
12
|
-
attr_reader :hints
|
13
|
-
|
14
|
-
# @option options [String] :validator_client
|
15
|
-
# @option options [String] :validator_path
|
16
|
-
# filepath to the validator used to bootstrap the node (required)
|
17
|
-
# @option options [String] :bootstrap_proxy (nil)
|
18
|
-
# URL to a proxy server to bootstrap through
|
19
|
-
# @option options [String] :encrypted_data_bag_secret
|
20
|
-
# your organizations encrypted data bag secret
|
21
|
-
# @option options [Hash] :hints (Hash.new)
|
22
|
-
# a hash of Ohai hints to place on the bootstrapped node
|
23
|
-
# @option options [Hash] :attributes (Hash.new)
|
24
|
-
# a hash of attributes to use in the first Chef run
|
25
|
-
# @option options [Array] :run_list (Array.new)
|
26
|
-
# an initial run list to bootstrap with
|
27
|
-
# @option options [String] :chef_version (nil)
|
28
|
-
# version of Chef to install on the node
|
29
|
-
# @option options [String] :environment ('_default')
|
30
|
-
# environment to join the node to
|
31
|
-
# @option options [Boolean] :sudo (true)
|
32
|
-
# bootstrap with sudo (default: true)
|
33
|
-
# @option options [String] :template ('unix_omnibus')
|
34
|
-
# bootstrap template to use
|
35
|
-
def initialize(options = {})
|
36
|
-
options = self.class.default_options.merge(options)
|
37
|
-
options[:template] ||= default_template
|
38
|
-
self.class.validate_options(options)
|
39
|
-
|
40
|
-
@template_file = options[:template]
|
41
|
-
@bootstrap_proxy = options[:bootstrap_proxy]
|
42
|
-
@chef_version = options[:chef_version]
|
43
|
-
@sudo = options[:sudo]
|
44
|
-
@validator_path = options[:validator_path]
|
45
|
-
@encrypted_data_bag_secret = options[:encrypted_data_bag_secret]
|
46
|
-
@hints = options[:hints]
|
47
|
-
@server_url = options[:server_url]
|
48
|
-
@validator_client = options[:validator_client]
|
49
|
-
@node_name = options[:node_name]
|
50
|
-
@attributes = options[:attributes]
|
51
|
-
@run_list = options[:run_list]
|
52
|
-
@environment = options[:environment]
|
53
|
-
end
|
54
|
-
|
55
|
-
# @return [String]
|
56
|
-
def boot_command
|
57
|
-
cmd = template.evaluate(self)
|
58
|
-
|
59
|
-
if sudo
|
60
|
-
cmd = "sudo #{cmd}"
|
61
|
-
end
|
62
|
-
|
63
|
-
cmd
|
64
|
-
end
|
65
|
-
|
66
|
-
# @return [String]
|
67
|
-
def chef_config
|
68
|
-
body = <<-CONFIG
|
69
|
-
log_level :info
|
70
|
-
log_location STDOUT
|
71
|
-
chef_server_url "#{server_url}"
|
72
|
-
validation_client_name "#{validator_client}"
|
73
|
-
CONFIG
|
74
|
-
|
75
|
-
if node_name.present?
|
76
|
-
body << %Q{node_name "#{node_name}"\n}
|
77
|
-
else
|
78
|
-
body << "# Using default node name (fqdn)\n"
|
79
|
-
end
|
80
|
-
|
81
|
-
if bootstrap_proxy.present?
|
82
|
-
body << %Q{http_proxy "#{bootstrap_proxy}"\n}
|
83
|
-
body << %Q{https_proxy "#{bootstrap_proxy}"\n}
|
84
|
-
end
|
85
|
-
|
86
|
-
if encrypted_data_bag_secret.present?
|
87
|
-
body << %Q{encrypted_data_bag_secret "#{bootstrap_directory}/encrypted_data_bag_secret"\n}
|
88
|
-
end
|
89
|
-
|
90
|
-
body
|
91
|
-
end
|
92
|
-
|
93
|
-
# @return [String]
|
94
|
-
def bootstrap_directory
|
95
|
-
"/etc/chef"
|
96
|
-
end
|
97
|
-
|
98
|
-
# @return [String]
|
99
|
-
def chef_run
|
100
|
-
"chef-client -j #{bootstrap_directory}/first-boot.json -E #{environment}"
|
101
|
-
end
|
102
|
-
|
103
|
-
# @return [String]
|
104
|
-
def default_template
|
105
|
-
templates_path.join('unix_omnibus.erb').to_s
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|