ssp 0.2 → 0.3
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/lib/ssp/application/chef.rb +55 -0
- data/lib/ssp/application/node.rb +5 -5
- data/lib/ssp/application/office_node.rb +8 -7
- data/lib/ssp/version.rb +1 -1
- metadata +5 -4
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'chef/config'
|
2
|
+
require 'chef/search/query'
|
3
|
+
require 'chef/node'
|
4
|
+
|
5
|
+
class SSP::App::Chef < Thor
|
6
|
+
namespace :chef
|
7
|
+
|
8
|
+
class_option :chef_config, :aliases => "-c",
|
9
|
+
:desc => "Location of the knife configuration file",
|
10
|
+
:default => File.join(ENV['HOME'], '.chef', 'knife.rb')
|
11
|
+
|
12
|
+
|
13
|
+
desc "client [NODES...]", "Runs chef-client on multiple nodes"
|
14
|
+
method_option :ssh_user, :aliases => "-u",
|
15
|
+
:desc => "The ssh username",
|
16
|
+
:default => "root"
|
17
|
+
method_option :ssh_password, :aliases => "-p",
|
18
|
+
:desc => "The ssh password"
|
19
|
+
def client(*nodes)
|
20
|
+
chef_config
|
21
|
+
command = options[:ssh_user] == "root" ? "chef-client" : "sudo chef-client"
|
22
|
+
ssh_run nodes.join(" "), command
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def ssh_run(host, command, user = options[:ssh_user], pass = options[:ssh_password], manual = !host.index(':'))
|
27
|
+
ssh = ::Chef::Knife::Ssh.new
|
28
|
+
ssh.name_args = [ host, command ]
|
29
|
+
ssh.config[:ssh_user] = user
|
30
|
+
ssh.config[:password] = pass
|
31
|
+
ssh.config[:manual] = manual
|
32
|
+
|
33
|
+
begin
|
34
|
+
ssh.run
|
35
|
+
rescue Net::SSH::AuthenticationFailed
|
36
|
+
unless pass
|
37
|
+
puts "Failed to authenticate #{user} - trying password auth"
|
38
|
+
ssh = ::Chef::Knife::Ssh.new
|
39
|
+
ssh.name_args = [ host, command ]
|
40
|
+
ssh.config[:ssh_user] = user
|
41
|
+
ssh.config[:manual] = manual
|
42
|
+
ssh.config[:password] = ssh.get_password
|
43
|
+
ssh.run
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def chef_config
|
49
|
+
unless defined?(@_chef_config_loaded)
|
50
|
+
::Chef::Config.from_file(options[:chef_config])
|
51
|
+
@_chef_config_loaded = true
|
52
|
+
end
|
53
|
+
::Chef::Config
|
54
|
+
end
|
55
|
+
end
|
data/lib/ssp/application/node.rb
CHANGED
@@ -44,8 +44,8 @@ echo "$IP #{fqdn} #{fqdn.split(".").first}" >> /etc/hosts
|
|
44
44
|
EOH
|
45
45
|
if chef_config[:chef_server_url] == "https://chef-server.rackspace"
|
46
46
|
chef_server_ip = %x{dscl . read Hosts/chef-server.rackspace 2>/dev/null}[/[\d\.]+/]
|
47
|
-
setup_node_script << %{echo "#{chef_server_ip} chef.
|
48
|
-
chef_config[:chef_server_url] = "https://chef.
|
47
|
+
setup_node_script << %{echo "#{chef_server_ip} chef.sspti.me" >> /etc/hosts\n}
|
48
|
+
chef_config[:chef_server_url] = "https://chef.sspti.me"
|
49
49
|
end
|
50
50
|
setup_node_script << "exit 0\n"
|
51
51
|
|
@@ -101,7 +101,7 @@ validation_client_name "#{chef_config[:validation_client_name]}"
|
|
101
101
|
|
102
102
|
say "\nBootstrapping #{shell.set_color(server.name, :bold)}..."
|
103
103
|
|
104
|
-
ssh = Chef::Knife::Ssh.new
|
104
|
+
ssh = ::Chef::Knife::Ssh.new
|
105
105
|
ssh.name_args = [ server.addresses["public"][0], "/bin/bash /etc/setup-node && /usr/local/bin/chef-client -j /etc/chef/first-boot.json" ]
|
106
106
|
ssh.config[:ssh_user] = "root"
|
107
107
|
ssh.config[:manual] = true
|
@@ -133,9 +133,9 @@ validation_client_name "#{chef_config[:validation_client_name]}"
|
|
133
133
|
|
134
134
|
def chef_config
|
135
135
|
unless defined?(@_chef_config_loaded)
|
136
|
-
Chef::Config.from_file(options[:chef_config])
|
136
|
+
::Chef::Config.from_file(options[:chef_config])
|
137
137
|
@_chef_config_loaded = true
|
138
138
|
end
|
139
|
-
Chef::Config
|
139
|
+
::Chef::Config
|
140
140
|
end
|
141
141
|
end
|
@@ -73,7 +73,7 @@ cat <<'EOP'
|
|
73
73
|
127.0.0.1 localhost localhost.localdomain
|
74
74
|
#{ip} #{fqdn} #{fqdn.split(".").first}
|
75
75
|
|
76
|
-
192.168.1.82 basil basil.
|
76
|
+
192.168.1.82 basil basil.sspti.me chef.sspti.me
|
77
77
|
EOP
|
78
78
|
) > /etc/hosts
|
79
79
|
|
@@ -131,6 +131,7 @@ EOH
|
|
131
131
|
command = <<EOH
|
132
132
|
bash -c '
|
133
133
|
xm shutdown #{hostname}
|
134
|
+
umount /mnt/#{hostname}
|
134
135
|
sleep 3
|
135
136
|
rm /etc/xen/#{hostname}.cfg
|
136
137
|
lvremove -f vg/#{hostname}-{root,swap}'
|
@@ -145,14 +146,14 @@ EOH
|
|
145
146
|
protected
|
146
147
|
def chef_config
|
147
148
|
unless defined?(@_chef_config_loaded)
|
148
|
-
Chef::Config.from_file(options[:chef_config])
|
149
|
+
::Chef::Config.from_file(options[:chef_config])
|
149
150
|
@_chef_config_loaded = true
|
150
151
|
end
|
151
|
-
Chef::Config
|
152
|
+
::Chef::Config
|
152
153
|
end
|
153
154
|
|
154
155
|
def ssh_run(host, command, user = options[:ssh_user], pass = options[:ssh_password])
|
155
|
-
ssh = Chef::Knife::Ssh.new
|
156
|
+
ssh = ::Chef::Knife::Ssh.new
|
156
157
|
ssh.name_args = [ host, command ]
|
157
158
|
ssh.config[:ssh_user] = user
|
158
159
|
ssh.config[:password] = pass
|
@@ -161,9 +162,9 @@ EOH
|
|
161
162
|
begin
|
162
163
|
ssh.run
|
163
164
|
rescue Net::SSH::AuthenticationFailed
|
164
|
-
unless
|
165
|
-
puts "Failed to authenticate #{
|
166
|
-
ssh = Chef::Knife::Ssh.new
|
165
|
+
unless pass
|
166
|
+
puts "Failed to authenticate #{user} - trying password auth"
|
167
|
+
ssh = ::Chef::Knife::Ssh.new
|
167
168
|
ssh.name_args = [ host, command ]
|
168
169
|
ssh.config[:ssh_user] = user
|
169
170
|
ssh.config[:manual] = true
|
data/lib/ssp/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ssp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- !binary |
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-07-
|
19
|
+
date: 2010-07-08 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- bin/ssp
|
64
64
|
- lib/ssp/app.rb
|
65
65
|
- lib/ssp/application/bags.rb
|
66
|
+
- lib/ssp/application/chef.rb
|
66
67
|
- lib/ssp/application/node.rb
|
67
68
|
- lib/ssp/application/office_node.rb
|
68
69
|
- lib/ssp/application/pair.rb
|