chef_cap 0.1.4 → 0.1.5

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.
@@ -1,3 +1,3 @@
1
1
  module ChefCap
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/recipes/chef_cap.rb CHANGED
@@ -46,20 +46,18 @@ if ChefDnaParser.parsed["environments"]
46
46
  end
47
47
  end
48
48
 
49
- private_key = ssh_deploy_key_file rescue false
50
- public_key = ssh_authorized_pub_file rescue false
51
- known_hosts = ssh_known_hosts rescue false
52
- if private_key || public_key || known_hosts
53
- private_key_remote_file = ".ssh/id_rsa"
54
- if private_key
55
- key_contents = File.read(private_key)
56
- private_key_remote_file = ".ssh/id_dsa" if key_contents =~ /DSA/i
57
- end
58
-
59
-
60
- namespace :ssh do
61
- desc "Transfer SSH keys to the remote server"
62
- task :transfer_keys do
49
+ namespace :ssh do
50
+ desc "Transfer SSH keys to the remote server"
51
+ task :transfer_keys do
52
+ private_key = ssh_deploy_key_file rescue false
53
+ public_key = ssh_authorized_pub_file rescue false
54
+ known_hosts = ssh_known_hosts rescue false
55
+ if private_key || public_key || known_hosts
56
+ private_key_remote_file = ".ssh/id_rsa"
57
+ if private_key
58
+ key_contents = File.read(private_key)
59
+ private_key_remote_file = ".ssh/id_dsa" if key_contents =~ /DSA/i
60
+ end
63
61
  run "mkdir -p ~/.ssh"
64
62
  if private_key
65
63
  put(File.read(private_key), private_key_remote_file, :mode => "0600")
@@ -67,18 +65,22 @@ if private_key || public_key || known_hosts
67
65
  put(File.read(public_key), ".ssh/authorized_keys", :mode => "0600") if public_key
68
66
  put(known_hosts, ".ssh/known_hosts", :mode => "0600") if known_hosts
69
67
  end
68
+ depend(:remote, :file, private_key_remote_file) if private_key
69
+ depend(:remote, :file, ".ssh/authorized_keys") if public_key
70
+ depend(:remote, :file, ".ssh/known_hosts") if known_hosts
70
71
  end
71
- before "chef:setup", "ssh:transfer_keys"
72
72
 
73
- depend(:remote, :file, private_key_remote_file) if private_key
74
- depend(:remote, :file, ".ssh/authorized_keys") if public_key
75
- depend(:remote, :file, ".ssh/known_hosts") if known_hosts
73
+ desc "Set any defined SSH options"
74
+ task :set_options do
75
+ ssh_options[:paranoid] = ssh_options_paranoid rescue nil
76
+ ssh_options[:keys] = ssh_options_keys rescue nil
77
+ ssh_options[:forward_agent] = ssh_options_forward_agent rescue nil
78
+ ssh_options[:username] = ssh_options_username rescue user rescue nil
79
+ ssh_options[:port] = ssh_options_port rescue nil
80
+ end
76
81
  end
77
-
78
- ssh_options[:paranoid] = ssh_options_paranoid rescue nil
79
- ssh_options[:keys] = ssh_options_keys rescue nil
80
- ssh_options[:forward_agent] = ssh_options_forward_agent rescue nil
81
- ssh_options[:username] = ssh_options_username rescue user rescue nil
82
+ before "chef:setup", "ssh:transfer_keys"
83
+ before "ssh:transfer_keys", "ssh:set_options"
82
84
 
83
85
  if ChefDnaParser.parsed["upload"]
84
86
  uploads_for_roles = {}
@@ -177,7 +179,7 @@ namespace :chef do
177
179
  set "node_hash_for_#{channel[:host].gsub(/\./, "_")}", json_to_modify
178
180
  put json_to_modify.to_json, "/tmp/chef-cap-#{rails_env}-#{channel[:host]}.json", :mode => "0600"
179
181
  end
180
- end
182
+ end
181
183
 
182
184
  chef.run_chef_solo
183
185
  end
@@ -92,6 +92,13 @@ def cap_role
92
92
  @servers ||= {}
93
93
  end
94
94
 
95
+ def unset(key)
96
+ @variables.delete(key)
97
+ self.instance_eval(<<-EOS)
98
+ undef #{key}
99
+ EOS
100
+ end
101
+
95
102
  def set(key, value)
96
103
  key.to_s.gsub!(/\.|-/, '_')
97
104
  self.instance_eval(<<-EOS)
@@ -178,58 +178,97 @@ describe "chef_cap" do
178
178
  "keys": "some_ssh_key_path"
179
179
  }
180
180
  }
181
+ },
182
+ "nossh": {
183
+ "ssh": {
184
+ "deploy_key_file": null
185
+ }
181
186
  }
182
187
  }
183
188
  }
184
189
  ERB
185
190
  end
186
191
 
187
- it "parses out the deploy private key" do
188
- chef_cap.cap_variable[:ssh_deploy_key_file].should_not be_nil
189
- chef_cap.cap_variable[:ssh_deploy_key_file].should == File.join(File.dirname(__FILE__), '..', 'fixtures', 'ssh_deploy_key')
190
- end
192
+ describe "ssh:transfer_keys" do
193
+ context "setting variables" do
194
+ before do
195
+ chef_cap.stub!(:put).and_return(true)
196
+ chef_cap.cap_task["ssh:transfer_keys"].call
197
+ end
191
198
 
192
- it "parses out the authorized public file" do
193
- chef_cap.cap_variable[:ssh_authorized_pub_file].should_not be_nil
194
- chef_cap.cap_variable[:ssh_authorized_pub_file].should == File.join(File.dirname(__FILE__), '..', 'fixtures', 'ssh_public_key')
195
- end
199
+ it "parses out the deploy private key" do
200
+ chef_cap.cap_variable[:ssh_deploy_key_file].should_not be_nil
201
+ chef_cap.cap_variable[:ssh_deploy_key_file].should == File.join(File.dirname(__FILE__), '..', 'fixtures', 'ssh_deploy_key')
202
+ end
196
203
 
197
- it "parses out the known hosts file" do
198
- chef_cap.cap_variable[:ssh_known_hosts].should_not be_nil
199
- chef_cap.cap_variable[:ssh_known_hosts].should == "knownhostscontent"
200
- end
204
+ it "parses out the authorized public file" do
205
+ chef_cap.cap_variable[:ssh_authorized_pub_file].should_not be_nil
206
+ chef_cap.cap_variable[:ssh_authorized_pub_file].should == File.join(File.dirname(__FILE__), '..', 'fixtures', 'ssh_public_key')
207
+ end
201
208
 
202
- it "creates a task that uploads the keys to the server users .ssh directory" do
203
- chef_cap.cap_namespace[:ssh].should be_true
204
- chef_cap.cap_task["ssh:transfer_keys"].should_not be_nil
205
- chef_cap.should_receive(:put).with("dsa imaprivatekey", ".ssh/id_dsa", :mode => "0600").and_return(true)
206
- chef_cap.should_receive(:put).with("imapublickey", ".ssh/authorized_keys", :mode => "0600").and_return(true)
207
- chef_cap.should_receive(:put).with("knownhostscontent", ".ssh/known_hosts", :mode => "0600").and_return(true)
209
+ it "parses out the known hosts file" do
210
+ chef_cap.cap_variable[:ssh_known_hosts].should_not be_nil
211
+ chef_cap.cap_variable[:ssh_known_hosts].should == "knownhostscontent"
212
+ end
213
+ end
208
214
 
209
- chef_cap.cap_task["ssh:transfer_keys"].call
210
- end
215
+ it "creates a task that uploads the keys to the server users .ssh directory" do
216
+ chef_cap.cap_namespace[:ssh].should be_true
217
+ chef_cap.cap_task["ssh:transfer_keys"].should_not be_nil
218
+ chef_cap.should_receive(:put).with("dsa imaprivatekey", ".ssh/id_dsa", :mode => "0600").and_return(true)
219
+ chef_cap.should_receive(:put).with("imapublickey", ".ssh/authorized_keys", :mode => "0600").and_return(true)
220
+ chef_cap.should_receive(:put).with("knownhostscontent", ".ssh/known_hosts", :mode => "0600").and_return(true)
211
221
 
212
- it "adds a before chef:setup hook that that uploads the keys on every deploy" do
213
- chef_cap.cap_before["chef:setup"].should_not be_nil
214
- chef_cap.cap_before["chef:setup"].should include("ssh:transfer_keys")
215
- end
222
+ chef_cap.cap_task["ssh:transfer_keys"].call
223
+ end
216
224
 
217
- it "adds dependencies on remote files for the ssh files to be uploaded" do
218
- chef_cap.cap_depends[".ssh/id_dsa"].should_not be_nil
219
- chef_cap.cap_depends[".ssh/id_dsa"].should == { :remote => :file }
220
225
 
221
- chef_cap.cap_depends[".ssh/authorized_keys"].should_not be_nil
222
- chef_cap.cap_depends[".ssh/authorized_keys"].should == { :remote => :file }
226
+ it "adds a before chef:setup hook that that uploads the keys on every deploy" do
227
+ chef_cap.cap_before["chef:setup"].should_not be_nil
228
+ chef_cap.cap_before["chef:setup"].should include("ssh:transfer_keys")
229
+ end
230
+
231
+ it "adds dependencies on remote files for the ssh files to be uploaded" do
232
+ chef_cap.stub(:put).and_return(true)
233
+ chef_cap.cap_task["ssh:transfer_keys"].call
234
+ chef_cap.cap_depends[".ssh/id_dsa"].should_not be_nil
235
+ chef_cap.cap_depends[".ssh/id_dsa"].should == { :remote => :file }
223
236
 
224
- chef_cap.cap_depends[".ssh/known_hosts"].should_not be_nil
225
- chef_cap.cap_depends[".ssh/known_hosts"].should == { :remote => :file }
237
+ chef_cap.cap_depends[".ssh/authorized_keys"].should_not be_nil
238
+ chef_cap.cap_depends[".ssh/authorized_keys"].should == { :remote => :file }
239
+
240
+ chef_cap.cap_depends[".ssh/known_hosts"].should_not be_nil
241
+ chef_cap.cap_depends[".ssh/known_hosts"].should == { :remote => :file }
242
+ end
226
243
  end
227
244
 
228
- describe "ssh_options" do
245
+ describe "ssh:set_options" do
229
246
  it "parses out keys" do
247
+ chef_cap.cap_task["ssh:set_options"].call
230
248
  chef_cap.cap_ssh_options[:keys].should_not be_nil
231
249
  chef_cap.cap_ssh_options[:keys].should == "some_ssh_key_path"
232
250
  end
251
+
252
+
253
+ it "adds a before ssh:transfer_keys hook to call ssh:set_options" do
254
+ chef_cap.cap_before["ssh:transfer_keys"].should_not be_nil
255
+ chef_cap.cap_before["ssh:transfer_keys"].should include("ssh:set_options")
256
+ end
257
+ end
258
+
259
+ context "when a value is null" do
260
+ it "will be not be uploaded" do
261
+ chef_cap.cap_variable[:ssh_deploy_key_file].should_not be_nil
262
+ chef_cap.cap_task[:nossh].call
263
+ chef_cap.cap_variable[:ssh_deploy_key_file].should be_nil
264
+
265
+ chef_cap.should_not_receive(:put).with("dsa imaprivatekey", ".ssh/id_dsa", :mode => "0600")
266
+ chef_cap.should_receive(:put).with("imapublickey", ".ssh/authorized_keys", :mode => "0600").and_return(true)
267
+ chef_cap.should_receive(:put).with("knownhostscontent", ".ssh/known_hosts", :mode => "0600").and_return(true)
268
+
269
+ chef_cap.cap_task["ssh:transfer_keys"].call
270
+ chef_cap.cap_variable[:ssh_deploy_key_file].should be_nil
271
+ end
233
272
  end
234
273
 
235
274
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Case Commons, LLC
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-01 00:00:00 -05:00
17
+ date: 2011-03-03 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency