chef 0.9.8 → 0.9.10.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/distro/common/man/man8/knife.8 +89 -79
- data/distro/common/markdown/knife.mkd +7 -0
- data/distro/debian/etc/default/chef-server +3 -0
- data/distro/debian/etc/default/chef-server-webui +3 -0
- data/distro/debian/etc/default/chef-solr +3 -0
- data/distro/debian/etc/default/chef-solr-indexer +3 -0
- data/distro/debian/etc/init.d/chef-server +3 -1
- data/distro/debian/etc/init.d/chef-server-webui +3 -1
- data/distro/redhat/etc/init.d/chef-client +1 -1
- data/lib/chef/application.rb +2 -0
- data/lib/chef/application/client.rb +5 -3
- data/lib/chef/application/knife.rb +16 -5
- data/lib/chef/application/solo.rb +0 -1
- data/lib/chef/checksum.rb +65 -1
- data/lib/chef/checksum_cache.rb +173 -0
- data/lib/chef/client.rb +84 -121
- data/lib/chef/cookbook/remote_file_vendor.rb +10 -3
- data/lib/chef/cookbook/syntax_check.rb +2 -2
- data/lib/chef/cookbook_loader.rb +2 -0
- data/lib/chef/cookbook_site_streaming_uploader.rb +29 -0
- data/lib/chef/cookbook_uploader.rb +8 -7
- data/lib/chef/cookbook_version.rb +155 -114
- data/lib/chef/exceptions.rb +5 -0
- data/lib/chef/handler.rb +43 -0
- data/lib/chef/index_queue/consumer.rb +1 -1
- data/lib/chef/index_queue/indexable.rb +1 -1
- data/lib/chef/knife.rb +18 -5
- data/lib/chef/knife/bootstrap.rb +2 -2
- data/lib/chef/knife/bootstrap/archlinux-gems.erb +44 -0
- data/lib/chef/knife/bootstrap/client-install.vbs +80 -0
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
- data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +6 -7
- data/lib/chef/knife/bootstrap/windows-gems.erb +34 -0
- data/lib/chef/knife/configure_client.rb +4 -2
- data/lib/chef/knife/cookbook_metadata.rb +1 -1
- data/lib/chef/knife/cookbook_site_share.rb +2 -1
- data/lib/chef/knife/cookbook_site_vendor.rb +6 -0
- data/lib/chef/knife/cookbook_test.rb +1 -1
- data/lib/chef/knife/ec2_server_create.rb +51 -26
- data/lib/chef/knife/exec.rb +52 -0
- data/lib/chef/knife/ssh.rb +27 -15
- data/lib/chef/knife/status.rb +27 -10
- data/lib/chef/knife/windows_bootstrap.rb +154 -0
- data/lib/chef/mixin/checksum.rb +2 -2
- data/lib/chef/mixin/xml_escape.rb +75 -49
- data/lib/chef/node.rb +54 -58
- data/lib/chef/node/attribute.rb +61 -53
- data/lib/chef/platform.rb +19 -2
- data/lib/chef/provider/breakpoint.rb +1 -1
- data/lib/chef/provider/cookbook_file.rb +3 -3
- data/lib/chef/provider/cron.rb +3 -3
- data/lib/chef/provider/cron/solaris.rb +195 -0
- data/lib/chef/provider/deploy.rb +3 -3
- data/lib/chef/provider/directory.rb +2 -2
- data/lib/chef/provider/env.rb +5 -5
- data/lib/chef/provider/execute.rb +1 -1
- data/lib/chef/provider/file.rb +10 -9
- data/lib/chef/provider/git.rb +12 -4
- data/lib/chef/provider/group.rb +5 -5
- data/lib/chef/provider/http_request.rb +25 -9
- data/lib/chef/provider/ifconfig.rb +2 -2
- data/lib/chef/provider/link.rb +11 -6
- data/lib/chef/provider/log.rb +1 -0
- data/lib/chef/provider/mdadm.rb +3 -3
- data/lib/chef/provider/mount.rb +5 -5
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/ohai.rb +41 -0
- data/lib/chef/provider/package.rb +5 -5
- data/lib/chef/provider/package/yum-dump.py +5 -2
- data/lib/chef/provider/remote_directory.rb +11 -5
- data/lib/chef/provider/remote_file.rb +2 -2
- data/lib/chef/provider/route.rb +154 -133
- data/lib/chef/provider/ruby_block.rb +1 -1
- data/lib/chef/provider/service.rb +6 -6
- data/lib/chef/provider/subversion.rb +12 -9
- data/lib/chef/provider/template.rb +2 -2
- data/lib/chef/provider/user.rb +7 -7
- data/lib/chef/provider/user/useradd.rb +15 -1
- data/lib/chef/providers.rb +2 -0
- data/lib/chef/resource.rb +164 -58
- data/lib/chef/resource/http_request.rb +9 -0
- data/lib/chef/resource/ohai.rb +40 -0
- data/lib/chef/resource/remote_directory.rb +10 -1
- data/lib/chef/resource/rpm_package.rb +34 -0
- data/lib/chef/resource_collection.rb +3 -2
- data/lib/chef/resources.rb +2 -0
- data/lib/chef/rest.rb +13 -7
- data/lib/chef/rest/auth_credentials.rb +1 -1
- data/lib/chef/rest/rest_request.rb +3 -1
- data/lib/chef/runner.rb +31 -55
- data/lib/chef/shef/shef_session.rb +1 -1
- data/lib/chef/util/windows/net_use.rb +1 -1
- data/lib/chef/version.rb +1 -1
- data/lib/chef/webui_user.rb +0 -1
- metadata +38 -19
- data/lib/chef/cache.rb +0 -61
- data/lib/chef/cache/checksum.rb +0 -91
data/lib/chef/knife/bootstrap.rb
CHANGED
@@ -116,11 +116,11 @@ class Chef
|
|
116
116
|
require 'highline'
|
117
117
|
|
118
118
|
if @name_args.first == nil
|
119
|
-
Chef::Log.error("Must pass
|
119
|
+
Chef::Log.error("Must pass an FQDN or ip to bootstrap")
|
120
120
|
exit 1
|
121
121
|
end
|
122
122
|
|
123
|
-
config[:server_name] = @name_args.first
|
123
|
+
config[:server_name] = Array(@name_args).first
|
124
124
|
|
125
125
|
$stdout.sync = true
|
126
126
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
bash -c '
|
2
|
+
if [ ! -f /usr/bin/chef-client ]; then
|
3
|
+
pacman -Syy
|
4
|
+
pacman -S --noconfirm ruby ntp
|
5
|
+
ntpdate pool.ntp.org
|
6
|
+
gem install ohai chef --no-rdoc --no-ri --verbose <%= '--prerelease' if @config[:prerelease] %>
|
7
|
+
fi
|
8
|
+
|
9
|
+
mkdir -p /etc/chef
|
10
|
+
(
|
11
|
+
cat <<'EOP'
|
12
|
+
<%= IO.read(Chef::Config[:validation_key]) %>
|
13
|
+
EOP
|
14
|
+
) > /tmp/validation.pem
|
15
|
+
awk NF /tmp/validation.pem > /etc/chef/validation.pem
|
16
|
+
rm /tmp/validation.pem
|
17
|
+
|
18
|
+
(
|
19
|
+
cat <<'EOP'
|
20
|
+
log_level :info
|
21
|
+
log_location STDOUT
|
22
|
+
chef_server_url "<%= Chef::Config[:chef_server_url] %>"
|
23
|
+
validation_client_name "<%= Chef::Config[:validation_client_name] %>"
|
24
|
+
<% if @config[:chef_node_name] == nil %>
|
25
|
+
# Using default node name (fqdn)
|
26
|
+
<% else %>
|
27
|
+
node_name "<%= @config[:chef_node_name] %>"
|
28
|
+
<% end %>
|
29
|
+
# ArchLinux follows the Filesystem Hierarchy Standard
|
30
|
+
file_cache_path "/var/cache/chef"
|
31
|
+
file_backup_path "/var/lib/chef/backup"
|
32
|
+
pid_file "/var/run/chef/client.pid"
|
33
|
+
cache_options({ :path => "/var/cache/chef/checksums", :skip_expires => true})
|
34
|
+
EOP
|
35
|
+
) > /etc/chef/client.rb
|
36
|
+
|
37
|
+
(
|
38
|
+
cat <<'EOP'
|
39
|
+
<%= { "run_list" => @run_list }.to_json %>
|
40
|
+
EOP
|
41
|
+
) > /etc/chef/first-boot.json
|
42
|
+
|
43
|
+
/usr/bin/chef-client -j /etc/chef/first-boot.json
|
44
|
+
'
|
@@ -0,0 +1,80 @@
|
|
1
|
+
'
|
2
|
+
' Author:: Doug MacEachern <dougm@vmware.com>
|
3
|
+
' Copyright:: Copyright (c) 2010 VMware, Inc.
|
4
|
+
' License:: Apache License, Version 2.0
|
5
|
+
'
|
6
|
+
' Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
' you may not use this file except in compliance with the License.
|
8
|
+
' You may obtain a copy of the License at
|
9
|
+
'
|
10
|
+
' http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
'
|
12
|
+
' Unless required by applicable law or agreed to in writing, software
|
13
|
+
' distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
' See the License for the specific language governing permissions and
|
16
|
+
' limitations under the License.
|
17
|
+
'
|
18
|
+
' download & install ruby && install chef client gems
|
19
|
+
|
20
|
+
Exe = "rubyinstaller-1.8.7-p249-rc2.exe"
|
21
|
+
Url = "http://rubyforge.org/frs/download.php/69034/" & Exe
|
22
|
+
Dst = "C:\Ruby"
|
23
|
+
Proxy = ""
|
24
|
+
If WScript.Arguments.Count = 1 Then
|
25
|
+
Proxy = WScript.Arguments.Item(0)
|
26
|
+
WScript.Echo "Using HTTP proxy=" & Proxy
|
27
|
+
End If
|
28
|
+
|
29
|
+
Set Shell = CreateObject("WScript.Shell")
|
30
|
+
Set Fs = CreateObject("Scripting.FileSystemObject")
|
31
|
+
If Fs.FileExists(Exe) Then
|
32
|
+
WScript.Echo "Using existing " & Exe
|
33
|
+
Else
|
34
|
+
WScript.Echo "Downloading " & Url
|
35
|
+
Set Http = CreateObject("WinHttp.WinHttpRequest.5.1")
|
36
|
+
If Proxy <> "" Then
|
37
|
+
Http.setProxy 2, Proxy, ""
|
38
|
+
End If
|
39
|
+
Http.Open "GET", Url, False
|
40
|
+
Http.Send
|
41
|
+
Set BinaryStream = CreateObject("ADODB.Stream")
|
42
|
+
BinaryStream.Type = 1
|
43
|
+
BinaryStream.Open
|
44
|
+
BinaryStream.Write Http.ResponseBody
|
45
|
+
BinaryStream.SaveToFile Exe, 2
|
46
|
+
BinaryStream.Close
|
47
|
+
End If
|
48
|
+
|
49
|
+
Ruby = Dst & "\bin\ruby.exe"
|
50
|
+
|
51
|
+
If Fs.FileExists(Ruby) Then
|
52
|
+
WScript.Echo Dst & " exists"
|
53
|
+
Else
|
54
|
+
WScript.Echo "Installing " & Exe & " to " & Dst
|
55
|
+
Cmd = Exe & " /dir=" & Dst & " /verysilent /tasks=assocfiles,modpath"
|
56
|
+
WScript.Echo Cmd
|
57
|
+
Set Exec = Shell.Exec(Cmd)
|
58
|
+
Do Until Exec.StdOut.AtEndOfStream
|
59
|
+
Line = Exec.StdOut.ReadLine()
|
60
|
+
Wscript.Echo Line
|
61
|
+
Loop
|
62
|
+
End If
|
63
|
+
|
64
|
+
GemProxy = ""
|
65
|
+
If Proxy <> "" Then
|
66
|
+
GemProxy = " --http-proxy=http://" & Proxy
|
67
|
+
End If
|
68
|
+
|
69
|
+
Cmd = Ruby & " " & Dst & "\bin\gem install" & GemProxy & " --no-ri --no-rdoc chef ruby-wmi windows-pr win32-open3 rubyzip"
|
70
|
+
WScript.Echo Cmd
|
71
|
+
Set Exec = Shell.Exec(Cmd)
|
72
|
+
Do Until Exec.StdOut.AtEndOfStream
|
73
|
+
Line = Exec.StdOut.ReadLine()
|
74
|
+
Wscript.Echo Line
|
75
|
+
Loop
|
76
|
+
Do Until Exec.StdErr.AtEndOfStream
|
77
|
+
Line = Exec.StdErr.ReadLine()
|
78
|
+
Wscript.Echo Line
|
79
|
+
Loop
|
80
|
+
|
@@ -3,9 +3,9 @@ if [ ! -f /usr/bin/chef-client ]; then
|
|
3
3
|
echo "chef chef/chef_server_url string <%= Chef::Config[:chef_server_url] %>" | debconf-set-selections
|
4
4
|
[ -f /etc/apt/sources.list.d/opscode.list ] || echo "deb http://apt.opscode.com lucid main" > /etc/apt/sources.list.d/opscode.list
|
5
5
|
wget -O- http://apt.opscode.com/packages@opscode.com.gpg.key | apt-key add -
|
6
|
-
apt-get update
|
7
|
-
apt-get install -y chef
|
8
6
|
fi
|
7
|
+
apt-get update
|
8
|
+
apt-get install -y chef
|
9
9
|
|
10
10
|
<% unless Chef::Config[:validation_client_name] == "chef-validator" -%>
|
11
11
|
[ `grep -qx "validation_client_name \"<%= Chef::Config[:validation_client_name] %>\"" /etc/chef/client.rb` ] || echo "validation_client_name \"<%= Chef::Config[:validation_client_name] %>\"" >> /etc/chef/client.rb
|
@@ -3,13 +3,12 @@ if [ ! -f /usr/bin/chef-client ]; then
|
|
3
3
|
apt-get update
|
4
4
|
apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras
|
5
5
|
cd /tmp
|
6
|
-
wget http://
|
7
|
-
tar
|
8
|
-
cd rubygems-1.3.
|
9
|
-
ruby setup.rb
|
10
|
-
cp /usr/bin/gem1.8 /usr/bin/gem
|
11
|
-
gem install ohai chef --no-rdoc --no-ri --verbose <%= '--prerelease' if @config[:prerelease] %>
|
6
|
+
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
|
7
|
+
tar zxf rubygems-1.3.7.tgz
|
8
|
+
cd rubygems-1.3.7
|
9
|
+
ruby setup.rb --no-format-executable
|
12
10
|
fi
|
11
|
+
gem install ohai chef --no-rdoc --no-ri --verbose <%= '--prerelease' if @config[:prerelease] %>
|
13
12
|
|
14
13
|
mkdir -p /etc/chef
|
15
14
|
|
@@ -41,4 +40,4 @@ cat <<'EOP'
|
|
41
40
|
EOP
|
42
41
|
) > /etc/chef/first-boot.json
|
43
42
|
|
44
|
-
/usr/bin/chef-client -j /etc/chef/first-boot.json'
|
43
|
+
/usr/bin/chef-client -j /etc/chef/first-boot.json'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
cscript /nologo client-install.vbs <%= @config[:proxy] %>
|
2
|
+
|
3
|
+
> c:/chef/etc/client.rb (
|
4
|
+
@echo.log_level :info
|
5
|
+
@echo.log_location STDOUT
|
6
|
+
@echo.chef_server_url "<%= Chef::Config[:chef_server_url] %>"
|
7
|
+
@echo.validation_client_name "<%= Chef::Config[:validation_client_name] %>"
|
8
|
+
@echo.client_key "c:/chef/etc/client.pem"
|
9
|
+
@echo.validation_key "c:/chef/etc/validation.pem"
|
10
|
+
@echo.checksum_path "c:/chef/var/checksums"
|
11
|
+
@echo.file_cache_path "c:/chef/var/cache"
|
12
|
+
@echo.file_backup_path "c:/chef/var/backup"
|
13
|
+
@echo.cache_options ^( {:path, "c:/chef/var/cache/checksums", :skip_expires, true} ^)
|
14
|
+
<% if Chef::Config[:http_proxy] != nil %>
|
15
|
+
@echo.http_proxy "<%= Chef::Config[:http_proxy] %>"
|
16
|
+
<% end %>
|
17
|
+
<% if Chef::Config[:https_proxy] != nil %>
|
18
|
+
@echo.https_proxy "<%= Chef::Config[:https_proxy] %>"
|
19
|
+
<% end %>
|
20
|
+
<% if Chef::Config[:no_proxy] != nil %>
|
21
|
+
@echo.no_proxy "<%= Chef::Config[:no_proxy] %>"
|
22
|
+
<% end %>
|
23
|
+
<% if @config[:chef_node_name] == nil %>
|
24
|
+
@echo.# Using default node name
|
25
|
+
<% else %>
|
26
|
+
@echo.node_name "<%= @config[:chef_node_name] %>"
|
27
|
+
<% end %>
|
28
|
+
)
|
29
|
+
|
30
|
+
> c:/chef/etc/first-boot.json (
|
31
|
+
@echo.<%= { "run_list" => @run_list }.to_json %>
|
32
|
+
)
|
33
|
+
|
34
|
+
c:/ruby/bin/ruby c:/ruby/bin/chef-client -c c:/chef/etc/client.rb -j c:/chef/etc/first-boot.json -l <%= Chef::Config[:log_level] %>"
|
@@ -31,7 +31,7 @@ class Chef
|
|
31
31
|
end
|
32
32
|
|
33
33
|
Chef::Log.info("Creating client configuration")
|
34
|
-
|
34
|
+
FileUtils.mkdir_p(@config_dir)
|
35
35
|
Chef::Log.info("Writing client.rb")
|
36
36
|
File.open(File.join(@config_dir, "client.rb"), "w") do |file|
|
37
37
|
file.puts('log_level :info')
|
@@ -40,7 +40,9 @@ class Chef
|
|
40
40
|
file.puts("validation_client_name '#{Chef::Config[:validation_client_name]}'")
|
41
41
|
end
|
42
42
|
Chef::Log.info("Writing validation.pem")
|
43
|
-
|
43
|
+
File.open(File.join(@config_dir, 'validation.pem'), "w") do |validation|
|
44
|
+
validation.puts(IO.read(Chef::Config[:validation_key]))
|
45
|
+
end
|
44
46
|
end
|
45
47
|
|
46
48
|
end
|
@@ -55,7 +55,7 @@ class Chef
|
|
55
55
|
|
56
56
|
def generate_metadata(cookbook)
|
57
57
|
Chef::Log.info("Generating Metadata")
|
58
|
-
config[:cookbook_path].reverse.each do |path|
|
58
|
+
Array(config[:cookbook_path]).reverse.each do |path|
|
59
59
|
file = File.expand_path(File.join(path, cookbook, 'metadata.rb'))
|
60
60
|
generate_metadata_from_file(cookbook, file)
|
61
61
|
end
|
@@ -46,8 +46,9 @@ class Chef
|
|
46
46
|
if cl.cookbook_exists?(cookbook_name)
|
47
47
|
cookbook = cl[cookbook_name]
|
48
48
|
Chef::CookbookUploader.validate_cookbook(cookbook)
|
49
|
-
tmp_cookbook_dir = Chef::
|
49
|
+
tmp_cookbook_dir = Chef::CookbookSiteStreamingUploader.create_build_dir(cookbook)
|
50
50
|
begin
|
51
|
+
Chef::Log.debug("temp cookbook directory is #{tmp_cookbook_dir.inspect}")
|
51
52
|
Chef::Log.info("Making tarball #{cookbook_name}.tgz")
|
52
53
|
Chef::Mixin::Command.run_command(:command => "tar -czf #{cookbook_name}.tgz #{cookbook_name}", :cwd => tmp_cookbook_dir)
|
53
54
|
rescue => e
|
@@ -45,6 +45,12 @@ class Chef
|
|
45
45
|
config[:cookbook_path] = Chef::Config[:cookbook_path]
|
46
46
|
end
|
47
47
|
|
48
|
+
# Check to ensure we have a valid source of cookbooks before continuing
|
49
|
+
unless File.directory?(config[:cookbook_path].first)
|
50
|
+
Chef::Log.error( File.join(config[:cookbook_path].first, " doesn't exist!. Make sure you have cookbook_path configured correctly"))
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
|
48
54
|
vendor_path = File.expand_path(File.join(config[:cookbook_path].first))
|
49
55
|
cookbook_path = File.join(vendor_path, name_args[0])
|
50
56
|
upstream_file = File.join(vendor_path, "#{name_args[0]}.tar.gz")
|
@@ -16,6 +16,7 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
+
require 'socket'
|
19
20
|
require 'chef/knife'
|
20
21
|
require 'json'
|
21
22
|
|
@@ -25,6 +26,8 @@ class Chef
|
|
25
26
|
|
26
27
|
banner "knife ec2 server create [RUN LIST...] (options)"
|
27
28
|
|
29
|
+
attr_accessor :initial_sleep_delay
|
30
|
+
|
28
31
|
option :flavor,
|
29
32
|
:short => "-f FLAVOR",
|
30
33
|
:long => "--flavor FLAVOR",
|
@@ -49,10 +52,15 @@ class Chef
|
|
49
52
|
:description => "The Availability Zone",
|
50
53
|
:default => "us-east-1b"
|
51
54
|
|
55
|
+
option :chef_node_name,
|
56
|
+
:short => "-N NAME",
|
57
|
+
:long => "--node-name NAME",
|
58
|
+
:description => "The Chef node name for your new node"
|
59
|
+
|
52
60
|
option :ssh_key_name,
|
53
61
|
:short => "-S KEY",
|
54
62
|
:long => "--ssh-key KEY",
|
55
|
-
:description => "The SSH
|
63
|
+
:description => "The AWS SSH key id",
|
56
64
|
:proc => Proc.new { |key| Chef::Config[:knife][:aws_ssh_key_id] = key }
|
57
65
|
|
58
66
|
option :ssh_user,
|
@@ -107,6 +115,25 @@ class Chef
|
|
107
115
|
@highline ||= HighLine.new
|
108
116
|
end
|
109
117
|
|
118
|
+
def tcp_test_ssh(hostname)
|
119
|
+
tcp_socket = TCPSocket.new(hostname, 22)
|
120
|
+
readable = IO.select([tcp_socket], nil, nil, 5)
|
121
|
+
if readable
|
122
|
+
Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
|
123
|
+
yield
|
124
|
+
true
|
125
|
+
else
|
126
|
+
false
|
127
|
+
end
|
128
|
+
rescue Errno::ETIMEDOUT
|
129
|
+
false
|
130
|
+
rescue Errno::ECONNREFUSED
|
131
|
+
sleep 2
|
132
|
+
false
|
133
|
+
ensure
|
134
|
+
tcp_socket && tcp_socket.close
|
135
|
+
end
|
136
|
+
|
110
137
|
def run
|
111
138
|
require 'fog'
|
112
139
|
require 'highline'
|
@@ -140,37 +167,21 @@ class Chef
|
|
140
167
|
|
141
168
|
# wait for it to be ready to do stuff
|
142
169
|
server.wait_for { print "."; ready? }
|
143
|
-
puts "#{h.color("\nWaiting 10 seconds for SSH Host Key generation on", :magenta)}: #{server.dns_name}"
|
144
|
-
sleep 10
|
145
170
|
|
146
|
-
|
171
|
+
puts("\n")
|
172
|
+
|
147
173
|
|
148
174
|
puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
|
149
175
|
puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}"
|
150
176
|
puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
|
151
177
|
puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
|
152
178
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
bootstrap.config[:chef_node_name] = server.id
|
160
|
-
bootstrap.config[:prerelease] = config[:prerelease]
|
161
|
-
bootstrap.config[:distro] = config[:distro]
|
162
|
-
bootstrap.config[:use_sudo] = true
|
163
|
-
bootstrap.config[:template_file] = config[:template_file]
|
164
|
-
bootstrap.run
|
165
|
-
rescue Errno::ECONNREFUSED
|
166
|
-
puts h.color("Connection refused on SSH, retrying - CTRL-C to abort")
|
167
|
-
sleep 1
|
168
|
-
retry
|
169
|
-
rescue Errno::ETIMEDOUT
|
170
|
-
puts h.color("Connection timed out on SSH, retrying - CTRL-C to abort")
|
171
|
-
sleep 1
|
172
|
-
retry
|
173
|
-
end
|
179
|
+
print "\n#{h.color("Waiting for sshd", :magenta)}"
|
180
|
+
|
181
|
+
print(".") until tcp_test_ssh(server.dns_name) { sleep @initial_sleep_delay ||= 10; puts("done") }
|
182
|
+
|
183
|
+
|
184
|
+
bootstrap_for_node(server).run
|
174
185
|
|
175
186
|
puts "\n"
|
176
187
|
puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
|
@@ -185,7 +196,21 @@ class Chef
|
|
185
196
|
puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
|
186
197
|
puts "#{h.color("Run List", :cyan)}: #{@name_args.join(', ')}"
|
187
198
|
end
|
199
|
+
|
200
|
+
def bootstrap_for_node(server)
|
201
|
+
bootstrap = Chef::Knife::Bootstrap.new
|
202
|
+
bootstrap.name_args = [server.dns_name]
|
203
|
+
bootstrap.config[:run_list] = @name_args
|
204
|
+
bootstrap.config[:ssh_user] = config[:ssh_user]
|
205
|
+
bootstrap.config[:identity_file] = config[:identity_file]
|
206
|
+
bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
|
207
|
+
bootstrap.config[:prerelease] = config[:prerelease]
|
208
|
+
bootstrap.config[:distro] = config[:distro]
|
209
|
+
bootstrap.config[:use_sudo] = true
|
210
|
+
bootstrap.config[:template_file] = config[:template_file]
|
211
|
+
bootstrap
|
212
|
+
end
|
213
|
+
|
188
214
|
end
|
189
215
|
end
|
190
216
|
end
|
191
|
-
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Daniel DeLeo (<dan@opscode.com)
|
3
|
+
# Copyright:: Copyright (c) 2010 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife'
|
20
|
+
|
21
|
+
class Chef::Knife::Exec < Chef::Knife
|
22
|
+
|
23
|
+
banner "knife exec [SCRIPT] (options)"
|
24
|
+
|
25
|
+
option :exec,
|
26
|
+
:short => "-E CODE",
|
27
|
+
:long => "--exec CODE",
|
28
|
+
:description => "a string of Chef code to execute"
|
29
|
+
|
30
|
+
def late_load_deps
|
31
|
+
require 'chef/shef/ext'
|
32
|
+
end
|
33
|
+
|
34
|
+
def run
|
35
|
+
late_load_deps
|
36
|
+
scripts = Array(name_args)
|
37
|
+
context = Object.new
|
38
|
+
Shef::Extensions.extend_context_object(context)
|
39
|
+
if config[:exec]
|
40
|
+
context.instance_eval(config[:exec], "-E Argument", 0)
|
41
|
+
elsif !scripts.empty?
|
42
|
+
scripts.each do |script|
|
43
|
+
file = File.expand_path(script)
|
44
|
+
context.instance_eval(IO.read(file), file, 0)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
script = STDIN.read
|
48
|
+
context.instance_eval(script, "STDIN", 0)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|