chef 0.8.16 → 0.9.0.a3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chef might be problematic. Click here for more details.
- data/bin/shef +1 -0
- data/distro/common/man/man1/chef-server-webui.1 +106 -0
- data/distro/common/man/man1/chef-server.1 +0 -1
- data/distro/common/man/man1/chef-solr-indexer.1 +55 -0
- data/distro/common/man/man1/chef-solr.1 +55 -0
- data/distro/common/man/man8/chef-client.8 +4 -2
- data/distro/common/man/man8/chef-solo.8 +1 -2
- data/distro/common/man/man8/chef-solr-rebuild.8 +37 -0
- data/distro/common/man/man8/knife.8 +668 -266
- data/distro/common/man/man8/shef.8 +45 -0
- data/distro/common/markdown/README +3 -0
- data/distro/common/markdown/knife.mkd +520 -0
- data/distro/debian/etc/default/chef-client +4 -0
- data/distro/debian/etc/default/chef-server +6 -0
- data/distro/debian/etc/default/chef-server-webui +6 -0
- data/distro/debian/etc/default/chef-solr +4 -0
- data/distro/debian/etc/default/chef-solr-indexer +4 -0
- data/distro/debian/etc/init.d/chef-client +41 -41
- data/distro/debian/etc/init.d/chef-server +10 -10
- data/distro/debian/etc/init.d/chef-server-webui +121 -0
- data/distro/debian/etc/init.d/chef-solr +177 -0
- data/distro/debian/etc/init.d/chef-solr-indexer +176 -0
- data/distro/redhat/etc/init.d/chef-client +76 -48
- data/distro/redhat/etc/init.d/chef-server +85 -51
- data/distro/redhat/etc/init.d/chef-server-webui +85 -51
- data/distro/redhat/etc/init.d/chef-solr +77 -49
- data/distro/redhat/etc/init.d/chef-solr-indexer +77 -48
- data/distro/redhat/etc/logrotate.d/chef-client +8 -0
- data/distro/redhat/etc/logrotate.d/chef-server +8 -0
- data/distro/redhat/etc/logrotate.d/chef-server-webui +8 -0
- data/distro/redhat/etc/logrotate.d/chef-solr +8 -0
- data/distro/redhat/etc/logrotate.d/chef-solr-indexer +8 -0
- data/distro/redhat/etc/sysconfig/chef-client +9 -4
- data/distro/redhat/etc/sysconfig/chef-server +10 -6
- data/distro/redhat/etc/sysconfig/chef-server-webui +10 -6
- data/distro/redhat/etc/sysconfig/chef-solr +3 -4
- data/distro/redhat/etc/sysconfig/chef-solr-indexer +3 -3
- data/lib/chef.rb +16 -5
- data/lib/chef/application/knife.rb +2 -2
- data/lib/chef/application/solo.rb +1 -7
- data/lib/chef/cache/checksum.rb +12 -5
- data/lib/chef/cache/file_cache_by_checksum.rb +52 -0
- data/lib/chef/checksum.rb +115 -0
- data/lib/chef/client.rb +193 -185
- data/lib/chef/config.rb +9 -1
- data/lib/chef/cookbook/cookbook_collection.rb +43 -0
- data/lib/chef/cookbook/file_system_file_vendor.rb +53 -0
- data/lib/chef/cookbook/file_vendor.rb +47 -0
- data/lib/chef/cookbook/metadata.rb +34 -35
- data/lib/chef/cookbook/metadata/version.rb +1 -1
- data/lib/chef/cookbook_loader.rb +70 -45
- data/lib/chef/cookbook_version.rb +760 -0
- data/lib/chef/couchdb.rb +8 -5
- data/lib/chef/data_bag_item.rb +5 -5
- data/lib/chef/exceptions.rb +10 -0
- data/lib/chef/file_access_control.rb +134 -0
- data/lib/chef/handler.rb +62 -0
- data/lib/chef/handler/json_file.rb +47 -0
- data/lib/chef/knife.rb +14 -2
- data/lib/chef/knife/bootstrap.rb +126 -0
- data/lib/chef/knife/cookbook_bulk_delete.rb +1 -1
- data/lib/chef/knife/cookbook_delete.rb +4 -4
- data/lib/chef/knife/cookbook_download.rb +57 -26
- data/lib/chef/knife/cookbook_metadata.rb +2 -2
- data/lib/chef/knife/cookbook_show.rb +30 -11
- data/lib/chef/knife/cookbook_upload.rb +113 -86
- data/lib/chef/knife/ec2_server_create.rb +146 -0
- data/lib/chef/knife/ec2_server_delete.rb +84 -0
- data/lib/chef/knife/ec2_server_list.rb +82 -0
- data/lib/chef/knife/status.rb +51 -0
- data/lib/chef/mixin/language_include_attribute.rb +16 -11
- data/lib/chef/mixin/language_include_recipe.rb +15 -16
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +17 -20
- data/lib/chef/mixin/shell_out.rb +38 -0
- data/lib/chef/mixins.rb +1 -1
- data/lib/chef/node.rb +190 -63
- data/lib/chef/node/attribute.rb +92 -78
- data/lib/chef/platform.rb +24 -4
- data/lib/chef/provider.rb +28 -10
- data/lib/chef/provider/breakpoint.rb +2 -2
- data/lib/chef/provider/cookbook_file.rb +96 -0
- data/lib/chef/provider/cron.rb +2 -2
- data/lib/chef/provider/deploy.rb +12 -10
- data/lib/chef/provider/env.rb +152 -0
- data/lib/chef/provider/env/windows.rb +75 -0
- data/lib/chef/provider/file.rb +10 -14
- data/lib/chef/provider/group.rb +15 -2
- data/lib/chef/provider/group/dscl.rb +17 -25
- data/lib/chef/provider/group/gpasswd.rb +6 -3
- data/lib/chef/provider/group/pw.rb +3 -7
- data/lib/chef/provider/group/windows.rb +79 -0
- data/lib/chef/provider/link.rb +4 -5
- data/lib/chef/provider/mdadm.rb +25 -18
- data/lib/chef/provider/mount/mount.rb +28 -27
- data/lib/chef/provider/package.rb +35 -35
- data/lib/chef/provider/package/dpkg.rb +13 -10
- data/lib/chef/provider/package/easy_install.rb +6 -6
- data/lib/chef/provider/package/freebsd.rb +17 -51
- data/lib/chef/provider/package/rpm.rb +1 -1
- data/lib/chef/provider/package/rubygems.rb +391 -74
- data/lib/chef/provider/package/yum.rb +2 -2
- data/lib/chef/provider/package/zypper.rb +2 -1
- data/lib/chef/provider/remote_directory.rb +60 -83
- data/lib/chef/provider/remote_file.rb +17 -66
- data/lib/chef/provider/script.rb +20 -9
- data/lib/chef/provider/service.rb +23 -30
- data/lib/chef/provider/service/arch.rb +3 -3
- data/lib/chef/provider/service/debian.rb +22 -17
- data/lib/chef/provider/service/freebsd.rb +4 -4
- data/lib/chef/provider/service/init.rb +2 -2
- data/lib/chef/provider/service/redhat.rb +14 -16
- data/lib/chef/provider/service/simple.rb +7 -3
- data/lib/chef/provider/service/solaris.rb +85 -0
- data/lib/chef/provider/service/upstart.rb +12 -7
- data/lib/chef/provider/service/windows.rb +2 -2
- data/lib/chef/provider/template.rb +133 -118
- data/lib/chef/provider/user.rb +34 -17
- data/lib/chef/provider/user/dscl.rb +117 -114
- data/lib/chef/provider/user/windows.rb +124 -0
- data/lib/chef/providers.rb +7 -0
- data/lib/chef/recipe.rb +39 -20
- data/lib/chef/resource.rb +47 -52
- data/lib/chef/resource/apt_package.rb +4 -4
- data/lib/chef/resource/bash.rb +4 -4
- data/lib/chef/resource/cookbook_file.rb +45 -0
- data/lib/chef/resource/cron.rb +3 -3
- data/lib/chef/resource/csh.rb +4 -4
- data/lib/chef/resource/deploy.rb +3 -3
- data/lib/chef/resource/directory.rb +4 -4
- data/lib/chef/resource/dpkg_package.rb +4 -4
- data/lib/chef/resource/easy_install_package.rb +3 -3
- data/lib/chef/resource/env.rb +58 -0
- data/lib/chef/resource/erl_call.rb +3 -3
- data/lib/chef/resource/execute.rb +3 -3
- data/lib/chef/resource/file.rb +3 -3
- data/lib/chef/resource/freebsd_package.rb +3 -3
- data/lib/chef/resource/gem_package.rb +17 -9
- data/lib/chef/resource/git.rb +3 -3
- data/lib/chef/resource/group.rb +3 -3
- data/lib/chef/resource/http_request.rb +4 -4
- data/lib/chef/resource/ifconfig.rb +3 -3
- data/lib/chef/resource/link.rb +3 -3
- data/lib/chef/resource/log.rb +2 -2
- data/lib/chef/resource/macports_package.rb +2 -2
- data/lib/chef/resource/mdadm.rb +3 -3
- data/lib/chef/resource/mount.rb +2 -2
- data/lib/chef/resource/package.rb +4 -4
- data/lib/chef/resource/pacman_package.rb +4 -4
- data/lib/chef/resource/perl.rb +4 -4
- data/lib/chef/resource/portage_package.rb +4 -4
- data/lib/chef/resource/python.rb +4 -4
- data/lib/chef/resource/remote_directory.rb +3 -3
- data/lib/chef/resource/remote_file.rb +26 -3
- data/lib/chef/resource/route.rb +3 -3
- data/lib/chef/resource/ruby.rb +3 -3
- data/lib/chef/resource/ruby_block.rb +3 -2
- data/lib/chef/resource/scm.rb +7 -5
- data/lib/chef/resource/script.rb +4 -4
- data/lib/chef/resource/service.rb +3 -3
- data/lib/chef/resource/subversion.rb +4 -2
- data/lib/chef/resource/template.rb +3 -3
- data/lib/chef/resource/user.rb +3 -3
- data/lib/chef/resource/yum_package.rb +3 -3
- data/lib/chef/resource_collection.rb +9 -5
- data/lib/chef/resources.rb +2 -0
- data/lib/chef/rest.rb +4 -0
- data/lib/chef/role.rb +2 -0
- data/lib/chef/run_context.rb +108 -0
- data/lib/chef/run_list.rb +75 -98
- data/lib/chef/run_list/run_list_expansion.rb +156 -0
- data/lib/chef/run_list/run_list_item.rb +71 -0
- data/lib/chef/runner.rb +58 -61
- data/lib/chef/sandbox.rb +147 -0
- data/lib/chef/shef.rb +4 -3
- data/lib/chef/shef/ext.rb +12 -4
- data/lib/chef/shef/shef_session.rb +27 -23
- data/lib/chef/shell_out.rb +375 -0
- data/lib/chef/util/windows.rb +56 -0
- data/lib/chef/util/windows/net_group.rb +101 -0
- data/lib/chef/util/windows/net_user.rb +198 -0
- data/lib/chef/version.rb +20 -0
- metadata +112 -22
- data/lib/chef/compile.rb +0 -158
- data/lib/chef/cookbook.rb +0 -201
- data/lib/chef/mixin/generate_url.rb +0 -58
data/lib/chef/couchdb.rb
CHANGED
@@ -97,6 +97,7 @@ class Chef
|
|
97
97
|
true
|
98
98
|
end
|
99
99
|
|
100
|
+
# Save the object to Couch. Add to index if the object supports it.
|
100
101
|
def store(obj_type, name, object)
|
101
102
|
validate(
|
102
103
|
{
|
@@ -109,12 +110,14 @@ class Chef
|
|
109
110
|
}
|
110
111
|
)
|
111
112
|
rows = get_view("id_map", "name_to_id", :key => [ obj_type, name ])["rows"]
|
112
|
-
uuid
|
113
|
-
|
113
|
+
uuid = rows.empty? ? UUIDTools::UUID.random_create.to_s : rows.first.fetch("id")
|
114
|
+
|
114
115
|
db_put_response = @rest.put_rest("#{couchdb_database}/#{uuid}", object)
|
115
|
-
|
116
|
-
|
117
|
-
|
116
|
+
|
117
|
+
if object.respond_to?(:add_to_index)
|
118
|
+
Chef::Log.info("Sending #{obj_type}(#{uuid}) to the index queue for addition.")
|
119
|
+
object.add_to_index(:database => couchdb_database, :id => uuid, :type => obj_type)
|
120
|
+
end
|
118
121
|
|
119
122
|
db_put_response
|
120
123
|
end
|
data/lib/chef/data_bag_item.rb
CHANGED
@@ -84,9 +84,9 @@ class Chef
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def raw_data=(new_data)
|
87
|
-
raise
|
88
|
-
raise
|
89
|
-
raise
|
87
|
+
raise Exceptions::ValidationFailed, "Data Bag Items must contain a Hash or Mash!" unless new_data.kind_of?(Hash) || new_data.kind_of?(Mash)
|
88
|
+
raise Exceptions::ValidationFailed, "Data Bag Items must have an id key in the hash! #{new_data.inspect}" unless new_data.has_key?("id")
|
89
|
+
raise Exceptions::ValidationFailed, "Data Bag Item id does not match alphanumeric/-/_!" unless new_data["id"] =~ /^[\-[:alnum:]_]+$/
|
90
90
|
@raw_data = new_data
|
91
91
|
end
|
92
92
|
|
@@ -103,8 +103,8 @@ class Chef
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def object_name
|
106
|
-
raise
|
107
|
-
raise
|
106
|
+
raise Exceptions::ValidationFailed, "You must have an 'id' or :id key in the raw data" unless raw_data.has_key?('id')
|
107
|
+
raise Exceptions::ValidationFailed, "You must have declared what bag this item belongs to!" unless data_bag
|
108
108
|
|
109
109
|
id = raw_data['id']
|
110
110
|
"data_bag_item_#{data_bag}_#{id}"
|
data/lib/chef/exceptions.rb
CHANGED
@@ -19,6 +19,7 @@ class Chef
|
|
19
19
|
class Exceptions
|
20
20
|
class Application < RuntimeError; end
|
21
21
|
class Cron < RuntimeError; end
|
22
|
+
class Env < RuntimeError; end
|
22
23
|
class Exec < RuntimeError; end
|
23
24
|
class FileNotFound < RuntimeError; end
|
24
25
|
class Package < RuntimeError; end
|
@@ -42,5 +43,14 @@ class Chef
|
|
42
43
|
class RedirectLimitExceeded < RuntimeError; end
|
43
44
|
class AmbiguousRunlistSpecification < ArgumentError; end
|
44
45
|
class CookbookNotFound < RuntimeError; end
|
46
|
+
class AttributeNotFound < RuntimeError; end
|
47
|
+
class InvalidCommandOption < RuntimeError; end
|
48
|
+
class CommandTimeout < RuntimeError; end
|
49
|
+
class ShellCommandFailed < RuntimeError; end
|
50
|
+
class RequestedUIDUnavailable < RuntimeError; end
|
51
|
+
class InvalidHomeDirectory < ArgumentError; end
|
52
|
+
class DsclCommandFailed < RuntimeError; end
|
53
|
+
class UserIDNotFound < ArgumentError; end
|
54
|
+
class GroupIDNotFound < ArgumentError; end
|
45
55
|
end
|
46
56
|
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Author:: Daniel DeLeo (<dan@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2008, 2010 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
class Chef
|
20
|
+
|
21
|
+
# FileAccessControl objects set the owner, group and mode of +file+ to
|
22
|
+
# the values specified by a value object, usually a Chef::Resource.
|
23
|
+
class FileAccessControl
|
24
|
+
UINT = (1 << 32)
|
25
|
+
UID_MAX = (1 << 30)
|
26
|
+
|
27
|
+
attr_reader :resource
|
28
|
+
|
29
|
+
attr_reader :file
|
30
|
+
|
31
|
+
# FileAccessControl objects set the owner, group and mode of +file+ to
|
32
|
+
# the values specified by +resource+. +file+ is completely independent
|
33
|
+
# of any file or path attribute on +resource+, so it is possible to set
|
34
|
+
# access control settings on a tempfile (for example).
|
35
|
+
# === Arguments:
|
36
|
+
# resource: probably a Chef::Resource::File object (or subclass), but
|
37
|
+
# this is not required. Must respond to +owner+, +group+,
|
38
|
+
# and +mode+
|
39
|
+
# file: The file whose access control settings you wish to modify,
|
40
|
+
# given as a String.
|
41
|
+
def initialize(resource, file)
|
42
|
+
@resource, @file = resource, file
|
43
|
+
@modified = false
|
44
|
+
end
|
45
|
+
|
46
|
+
def modified?
|
47
|
+
@modified
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_all
|
51
|
+
set_owner
|
52
|
+
set_group
|
53
|
+
set_mode
|
54
|
+
end
|
55
|
+
|
56
|
+
# Workaround the fact that Ruby's Etc module doesn't believe in negative
|
57
|
+
# uids, so negative uids show up as the diminished radix complement of
|
58
|
+
# the maximum fixnum size. For example, a uid of -2 is reported as
|
59
|
+
def dimished_radix_complement(int)
|
60
|
+
if int > UID_MAX
|
61
|
+
int - UINT
|
62
|
+
else
|
63
|
+
int
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def target_uid
|
68
|
+
return nil if resource.owner.nil?
|
69
|
+
if resource.owner.kind_of?(String)
|
70
|
+
dimished_radix_complement( Etc.getpwnam(resource.owner).uid )
|
71
|
+
elsif resource.owner.kind_of?(Integer)
|
72
|
+
resource.owner
|
73
|
+
else
|
74
|
+
raise ArgumentError, "cannot resolve #{resource.owner.inspect} to uid, owner must be a string or integer"
|
75
|
+
end
|
76
|
+
rescue ArgumentError
|
77
|
+
raise Chef::Exceptions::UserIDNotFound, "cannot resolve user id for '#{resource.owner}'"
|
78
|
+
end
|
79
|
+
|
80
|
+
def set_owner
|
81
|
+
if (uid = target_uid) && (uid != stat.uid)
|
82
|
+
Chef::Log.debug("setting owner on #{file} to #{uid}")
|
83
|
+
File.chown(uid, nil, file)
|
84
|
+
modified
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def target_gid
|
89
|
+
return nil if resource.group.nil?
|
90
|
+
if resource.group.kind_of?(String)
|
91
|
+
dimished_radix_complement( Etc.getgrnam(resource.group).gid )
|
92
|
+
elsif resource.group.kind_of?(Integer)
|
93
|
+
resource.group
|
94
|
+
else
|
95
|
+
raise ArgumentError, "cannot resolve #{resource.group.inspect} to gid, group must be a string or integer"
|
96
|
+
end
|
97
|
+
rescue ArgumentError
|
98
|
+
raise Chef::Exceptions::GroupIDNotFound, "cannot resolve group id for '#{resource.group}'"
|
99
|
+
end
|
100
|
+
|
101
|
+
def set_group
|
102
|
+
if (gid = target_gid) && (gid != stat.gid)
|
103
|
+
Chef::Log.debug("setting group on #{file} to #{gid}")
|
104
|
+
File.chown(nil, gid, file)
|
105
|
+
modified
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def target_mode
|
110
|
+
return nil if resource.mode.nil?
|
111
|
+
(resource.mode.respond_to?(:oct) ? resource.mode.oct : resource.mode.to_i) & 007777
|
112
|
+
end
|
113
|
+
|
114
|
+
def set_mode
|
115
|
+
if (mode = target_mode) && (mode != (stat.mode & 007777))
|
116
|
+
Chef::Log.debug("setting mode on #{file} to #{mode.to_s(8)}")
|
117
|
+
File.chmod(target_mode, file)
|
118
|
+
modified
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def stat
|
124
|
+
@stat ||= ::File.stat(file)
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def modified
|
130
|
+
@modified = true
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
data/lib/chef/handler.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@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
|
+
class Chef
|
20
|
+
class Handler
|
21
|
+
|
22
|
+
attr_accessor :config
|
23
|
+
|
24
|
+
def initialize(config={})
|
25
|
+
@config = config
|
26
|
+
@config[:path] ||= "/var/chef/reports"
|
27
|
+
@config
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_report_data(node, runner, start_time, end_time, elapsed_time, exception=nil)
|
31
|
+
data = Hash.new
|
32
|
+
data[:node] = node if node
|
33
|
+
if runner
|
34
|
+
data[:resources] = {
|
35
|
+
:all => runner.run_context.resource_collection.all_resources,
|
36
|
+
:updated => runner.run_context.resource_collection.inject([]) { |m, r| m << r if r.updated; m }
|
37
|
+
}
|
38
|
+
end
|
39
|
+
if exception
|
40
|
+
data[:success] = false
|
41
|
+
data[:exception] = {
|
42
|
+
:message => exception.message,
|
43
|
+
:backtrace => exception.backtrace
|
44
|
+
}
|
45
|
+
else
|
46
|
+
data[:success] = true
|
47
|
+
end
|
48
|
+
data[:elapsed_time] = elapsed_time
|
49
|
+
data[:start_time] = start_time
|
50
|
+
data[:end_time] = end_time
|
51
|
+
data
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_report_dir
|
55
|
+
unless File.exists?(config[:path])
|
56
|
+
FileUtils.mkdir_p(config[:path])
|
57
|
+
File.chmod(octal_mode("0700"), config[:path])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@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/handler'
|
20
|
+
require 'chef/resource/directory'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Handler
|
24
|
+
class JsonFile < ::Chef::Handler
|
25
|
+
|
26
|
+
def initialize(config={})
|
27
|
+
super(config)
|
28
|
+
end
|
29
|
+
|
30
|
+
def report(node, runner, start_time, end_time, elapsed_time, exception)
|
31
|
+
if exception
|
32
|
+
Chef::Log.error("Creating JSON exception report")
|
33
|
+
else
|
34
|
+
Chef::Log.info("Creating JSON run report")
|
35
|
+
end
|
36
|
+
|
37
|
+
data = build_report_data(node, runner, start_time, end_time, elapsed_time, exception)
|
38
|
+
build_report_dir
|
39
|
+
savetime = Time.now.strftime("%Y%m%d%H%M%S")
|
40
|
+
File.open(File.join(config[:path], "chef-run-report-#{savetime}.json"), "w") do |file|
|
41
|
+
file.puts JSON.pretty_generate(data)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/chef/knife.rb
CHANGED
@@ -112,10 +112,20 @@ class Chef
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def configure_chef
|
115
|
-
|
116
|
-
|
115
|
+
unless config[:config_file]
|
116
|
+
full_path = Dir.pwd.split(File::SEPARATOR)
|
117
|
+
(full_path.length - 1).downto(0) do |i|
|
118
|
+
config_file_to_check = File.join([ full_path[0..i], ".chef", "knife.rb" ].flatten)
|
119
|
+
if File.exists?(config_file_to_check)
|
120
|
+
config[:config_file] = config_file_to_check
|
121
|
+
break
|
122
|
+
end
|
123
|
+
end
|
124
|
+
config[:config_file] ||= File.join(ENV['HOME'], '.chef', 'knife.rb')
|
117
125
|
end
|
118
126
|
|
127
|
+
Chef::Config.from_file(config[:config_file])
|
128
|
+
|
119
129
|
Chef::Config[:log_level] = config[:log_level] if config[:log_level]
|
120
130
|
Chef::Config[:log_location] = config[:log_location] if config[:log_location]
|
121
131
|
Chef::Config[:node_name] = config[:node_name] if config[:node_name]
|
@@ -125,6 +135,8 @@ class Chef
|
|
125
135
|
Chef::Log.init(Chef::Config[:log_location])
|
126
136
|
Chef::Log.level(Chef::Config[:log_level])
|
127
137
|
|
138
|
+
Chef::Log.debug("Using configuration from #{config[:config_file]}")
|
139
|
+
|
128
140
|
if Chef::Config[:node_name].nil?
|
129
141
|
raise ArgumentError, "No user specified, pass via -u or specifiy 'node_name' in #{config[:config_file] ? config[:config_file] : "~/.chef/knife.rb"}"
|
130
142
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@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
|
+
require 'json'
|
21
|
+
require 'tempfile'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Knife
|
25
|
+
class Bootstrap < Knife
|
26
|
+
|
27
|
+
banner "Sub-Command: knife bootstrap FQDN [RUN LIST...] (options)"
|
28
|
+
|
29
|
+
option :ssh_user,
|
30
|
+
:short => "-x USERNAME",
|
31
|
+
:long => "--ssh-user USERNAME",
|
32
|
+
:description => "The ssh username",
|
33
|
+
:default => "root"
|
34
|
+
|
35
|
+
option :ssh_password,
|
36
|
+
:short => "-P PASSWORD",
|
37
|
+
:long => "--ssh-password PASSWORD",
|
38
|
+
:description => "The ssh password"
|
39
|
+
|
40
|
+
option :chef_node_name,
|
41
|
+
:short => "-N NAME",
|
42
|
+
:long => "--node-name NAME",
|
43
|
+
:description => "The Chef node name for your new node"
|
44
|
+
|
45
|
+
|
46
|
+
def h
|
47
|
+
@highline ||= HighLine.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def run
|
51
|
+
require 'highline'
|
52
|
+
|
53
|
+
server_name = @name_args[0]
|
54
|
+
|
55
|
+
puts "Bootstrapping Chef on #{h.color(server_name, :bold)}"
|
56
|
+
|
57
|
+
$stdout.sync = true
|
58
|
+
|
59
|
+
command = <<EOH
|
60
|
+
bash -c '
|
61
|
+
if [ ! -f /usr/bin/chef-client ]; then
|
62
|
+
apt-get update
|
63
|
+
apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras
|
64
|
+
cd /tmp
|
65
|
+
wget http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz
|
66
|
+
tar xvf rubygems-1.3.6.tgz
|
67
|
+
cd rubygems-1.3.6
|
68
|
+
ruby setup.rb
|
69
|
+
cp /usr/bin/gem1.8 /usr/bin/gem
|
70
|
+
gem install chef ohai --no-rdoc --no-ri --verbose
|
71
|
+
fi
|
72
|
+
|
73
|
+
mkdir -p /etc/chef
|
74
|
+
|
75
|
+
(
|
76
|
+
cat <<'EOP'
|
77
|
+
#{IO.read(Chef::Config[:validation_key])}
|
78
|
+
EOP
|
79
|
+
) > /tmp/validation.pem
|
80
|
+
awk NF /tmp/validation.pem > /etc/chef/validation.pem
|
81
|
+
rm /tmp/validation.pem
|
82
|
+
|
83
|
+
(
|
84
|
+
cat <<'EOP'
|
85
|
+
log_level :info
|
86
|
+
log_location STDOUT
|
87
|
+
chef_server_url "#{Chef::Config[:chef_server_url]}"
|
88
|
+
validation_client_name "#{Chef::Config[:validation_client_name]}"
|
89
|
+
#{config[:chef_node_name] == nil ? "# Using default node name" : "node_name \"#{config[:chef_node_name]}\""}
|
90
|
+
EOP
|
91
|
+
) > /etc/chef/client.rb
|
92
|
+
|
93
|
+
(
|
94
|
+
cat <<'EOP'
|
95
|
+
#{{ "run_list" => @name_args[1..-1] }.to_json}
|
96
|
+
EOP
|
97
|
+
) > /etc/chef/first-boot.json
|
98
|
+
|
99
|
+
/usr/bin/chef-client -j /etc/chef/first-boot.json'
|
100
|
+
EOH
|
101
|
+
|
102
|
+
ssh = Chef::Knife::Ssh.new
|
103
|
+
ssh.name_args = [ server_name, "sudo #{command}" ]
|
104
|
+
ssh.config[:ssh_user] = config[:ssh_user]
|
105
|
+
ssh.config[:password] = config[:ssh_password]
|
106
|
+
ssh.config[:manual] = true
|
107
|
+
|
108
|
+
begin
|
109
|
+
ssh.run
|
110
|
+
rescue Net::SSH::AuthenticationFailed
|
111
|
+
unless config[:ssh_password]
|
112
|
+
puts "Failed to authenticate #{config[:ssh_user]} - trying password auth"
|
113
|
+
ssh = Chef::Knife::Ssh.new
|
114
|
+
ssh.name_args = [ server_name, "sudo #{command}" ]
|
115
|
+
ssh.config[:ssh_user] = config[:ssh_user]
|
116
|
+
ssh.config[:manual] = true
|
117
|
+
ssh.config[:password] = ssh.get_password
|
118
|
+
ssh.run
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|