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/node/attribute.rb
CHANGED
@@ -23,37 +23,65 @@ require 'chef/log'
|
|
23
23
|
class Chef
|
24
24
|
class Node
|
25
25
|
class Attribute
|
26
|
-
attr_accessor :
|
26
|
+
attr_accessor :normal,
|
27
27
|
:default,
|
28
28
|
:override,
|
29
|
+
:automatic,
|
29
30
|
:state,
|
30
|
-
:
|
31
|
+
:current_normal,
|
31
32
|
:current_default,
|
32
33
|
:current_override,
|
34
|
+
:current_automatic,
|
33
35
|
:auto_vivifiy_on_read,
|
34
36
|
:set_unless_value_present,
|
35
|
-
:has_been_read
|
37
|
+
:has_been_read,
|
38
|
+
:set_type
|
36
39
|
|
37
40
|
include Enumerable
|
38
41
|
|
39
|
-
def initialize(
|
40
|
-
@
|
41
|
-
@
|
42
|
+
def initialize(normal, default, override, automatic, state=[])
|
43
|
+
@normal = normal
|
44
|
+
@current_normal = normal
|
42
45
|
@default = default
|
43
46
|
@current_default = default
|
44
47
|
@override = override
|
45
48
|
@current_override = override
|
49
|
+
@automatic = automatic
|
50
|
+
@current_automatic = automatic
|
46
51
|
@state = state
|
47
52
|
@auto_vivifiy_on_read = false
|
48
53
|
@set_unless_value_present = false
|
54
|
+
@set_type = :normal
|
49
55
|
@has_been_read = false
|
50
56
|
end
|
51
57
|
|
58
|
+
def attribute
|
59
|
+
normal
|
60
|
+
end
|
61
|
+
|
62
|
+
def attribute=(value)
|
63
|
+
normal = value
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_type_hash
|
67
|
+
case @set_type
|
68
|
+
when :normal
|
69
|
+
@normal
|
70
|
+
when :override
|
71
|
+
@override
|
72
|
+
when :default
|
73
|
+
@default
|
74
|
+
when :automatic
|
75
|
+
@automatic
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
52
79
|
# Reset our internal state to the top of every tree
|
53
80
|
def reset
|
54
|
-
@
|
81
|
+
@current_normal = @normal
|
55
82
|
@current_default = @default
|
56
83
|
@current_override = @override
|
84
|
+
@current_automatic = @automatic
|
57
85
|
@has_been_read = false
|
58
86
|
@state = []
|
59
87
|
end
|
@@ -65,16 +93,18 @@ class Chef
|
|
65
93
|
# See the comments in []= for more details.
|
66
94
|
@has_been_read = true
|
67
95
|
|
68
|
-
|
69
|
-
|
70
|
-
|
96
|
+
a_value = value_or_descend(current_automatic, key, auto_vivifiy_on_read && @set_type == :automatic)
|
97
|
+
o_value = value_or_descend(current_override, key, auto_vivifiy_on_read && @set_type == :override)
|
98
|
+
n_value = value_or_descend(current_normal, key, auto_vivifiy_on_read && @set_type == :normal)
|
99
|
+
d_value = value_or_descend(current_default, key, auto_vivifiy_on_read && @set_type == :default)
|
71
100
|
|
72
|
-
determine_value(o_value,
|
101
|
+
determine_value(a_value, o_value, n_value, d_value)
|
73
102
|
end
|
74
103
|
|
75
104
|
def attribute?(key)
|
105
|
+
return true if get_value(automatic, key)
|
76
106
|
return true if get_value(override, key)
|
77
|
-
return true if get_value(
|
107
|
+
return true if get_value(normal, key)
|
78
108
|
return true if get_value(default, key)
|
79
109
|
false
|
80
110
|
end
|
@@ -90,8 +120,9 @@ class Chef
|
|
90
120
|
def each(&block)
|
91
121
|
get_keys.each do |key|
|
92
122
|
value = determine_value(
|
123
|
+
get_value(automatic, key),
|
93
124
|
get_value(override, key),
|
94
|
-
get_value(
|
125
|
+
get_value(normal, key),
|
95
126
|
get_value(default, key)
|
96
127
|
)
|
97
128
|
block.call([key, value])
|
@@ -101,8 +132,9 @@ class Chef
|
|
101
132
|
def each_pair(&block)
|
102
133
|
get_keys.each do |key|
|
103
134
|
value = determine_value(
|
135
|
+
get_value(automatic, key),
|
104
136
|
get_value(override, key),
|
105
|
-
get_value(
|
137
|
+
get_value(normal, key),
|
106
138
|
get_value(default, key)
|
107
139
|
)
|
108
140
|
block.call(key, value)
|
@@ -112,8 +144,9 @@ class Chef
|
|
112
144
|
def each_attribute(&block)
|
113
145
|
get_keys.each do |key|
|
114
146
|
value = determine_value(
|
147
|
+
get_value(automatic, key),
|
115
148
|
get_value(override, key),
|
116
|
-
get_value(
|
149
|
+
get_value(normal, key),
|
117
150
|
get_value(default, key)
|
118
151
|
)
|
119
152
|
block.call(key, value)
|
@@ -129,8 +162,9 @@ class Chef
|
|
129
162
|
def each_value(&block)
|
130
163
|
get_keys.each do |key|
|
131
164
|
value = determine_value(
|
165
|
+
get_value(automatic, key),
|
132
166
|
get_value(override, key),
|
133
|
-
get_value(
|
167
|
+
get_value(normal, key),
|
134
168
|
get_value(default, key)
|
135
169
|
)
|
136
170
|
block.call(value)
|
@@ -144,8 +178,9 @@ class Chef
|
|
144
178
|
def fetch(key, default_value=nil, &block)
|
145
179
|
if get_keys.include? key
|
146
180
|
determine_value(
|
181
|
+
get_value(automatic, key),
|
147
182
|
get_value(override, key),
|
148
|
-
get_value(
|
183
|
+
get_value(normal, key),
|
149
184
|
get_value(default, key)
|
150
185
|
)
|
151
186
|
elsif default_value
|
@@ -201,18 +236,12 @@ class Chef
|
|
201
236
|
end
|
202
237
|
|
203
238
|
def keys
|
204
|
-
tkeys = []
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
tkeys << key unless tkeys.include?(key)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
if current_default
|
214
|
-
current_default.keys.each do |key|
|
215
|
-
tkeys << key unless tkeys.include?(key)
|
239
|
+
tkeys = current_automatic ? current_automatic.keys : []
|
240
|
+
[ current_override, current_normal, current_default ].each do |attr_hash|
|
241
|
+
if attr_hash
|
242
|
+
attr_hash.keys.each do |key|
|
243
|
+
tkeys << key unless tkeys.include?(key)
|
244
|
+
end
|
216
245
|
end
|
217
246
|
end
|
218
247
|
tkeys
|
@@ -249,47 +278,40 @@ class Chef
|
|
249
278
|
(! to_check.kind_of?(Chef::Node::Attribute)) && to_check.respond_to?(:has_key?)
|
250
279
|
end
|
251
280
|
|
252
|
-
def determine_value(o_value,
|
253
|
-
|
254
|
-
|
255
|
-
value = Chef::Mixin::DeepMerge.merge(
|
256
|
-
value = Chef::Mixin::DeepMerge.merge(value,
|
281
|
+
def determine_value(a_value, o_value, n_value, d_value)
|
282
|
+
if hash_and_not_cna?(a_value)
|
283
|
+
value = {}
|
284
|
+
value = Chef::Mixin::DeepMerge.merge(value, d_value) if hash_and_not_cna?(d_value)
|
285
|
+
value = Chef::Mixin::DeepMerge.merge(value, n_value) if hash_and_not_cna?(n_value)
|
286
|
+
value = Chef::Mixin::DeepMerge.merge(value, o_value) if hash_and_not_cna?(o_value)
|
287
|
+
value = Chef::Mixin::DeepMerge.merge(value, a_value)
|
257
288
|
value
|
258
|
-
|
259
|
-
|
260
|
-
Chef::Mixin::DeepMerge.merge(
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
# If we have an attribute value, use it
|
271
|
-
elsif ! a_value.nil?
|
272
|
-
a_value
|
273
|
-
# If we have a default value, use it
|
274
|
-
elsif ! d_value.nil?
|
289
|
+
elsif hash_and_not_cna?(o_value)
|
290
|
+
value = {}
|
291
|
+
value = Chef::Mixin::DeepMerge.merge(value, d_value) if hash_and_not_cna?(d_value)
|
292
|
+
value = Chef::Mixin::DeepMerge.merge(value, n_value) if hash_and_not_cna?(n_value)
|
293
|
+
value = Chef::Mixin::DeepMerge.merge(value, o_value)
|
294
|
+
value
|
295
|
+
elsif hash_and_not_cna?(n_value)
|
296
|
+
value = {}
|
297
|
+
value = Chef::Mixin::DeepMerge.merge(value, d_value) if hash_and_not_cna?(d_value)
|
298
|
+
value = Chef::Mixin::DeepMerge.merge(value, n_value)
|
299
|
+
value
|
300
|
+
elsif hash_and_not_cna?(d_value)
|
275
301
|
d_value
|
276
302
|
else
|
277
|
-
nil
|
303
|
+
return a_value if ! a_value.nil?
|
304
|
+
return o_value if ! o_value.nil?
|
305
|
+
return n_value if ! n_value.nil?
|
306
|
+
return d_value if ! d_value.nil?
|
307
|
+
return nil
|
278
308
|
end
|
279
309
|
end
|
280
310
|
|
281
311
|
def []=(key, value)
|
282
312
|
if set_unless_value_present
|
283
|
-
if get_value(
|
284
|
-
Chef::Log.debug("Not setting #{state.join("/")}/#{key} to #{value.inspect} because it has a
|
285
|
-
return false
|
286
|
-
end
|
287
|
-
if get_value(@attribute, key) != nil
|
288
|
-
Chef::Log.debug("Not setting #{state.join("/")}/#{key} to #{value.inspect} because it has a node attribute value already")
|
289
|
-
return false
|
290
|
-
end
|
291
|
-
if get_value(@override, key) != nil
|
292
|
-
Chef::Log.debug("Not setting #{state.join("/")}/#{key} to #{value.inspect} because it has an override value already")
|
313
|
+
if get_value(set_type_hash, key) != nil
|
314
|
+
Chef::Log.debug("Not setting #{state.join("/")}/#{key} to #{value.inspect} because it has a #{@set_type} value already")
|
293
315
|
return false
|
294
316
|
end
|
295
317
|
end
|
@@ -302,8 +324,7 @@ class Chef
|
|
302
324
|
# supporting one more single-use style.
|
303
325
|
@state.pop if @has_been_read && @state.last == key
|
304
326
|
|
305
|
-
set_value(
|
306
|
-
set_value(@override, key, value)
|
327
|
+
set_value(set_type_hash, key, value)
|
307
328
|
value
|
308
329
|
end
|
309
330
|
|
@@ -344,30 +365,23 @@ class Chef
|
|
344
365
|
end
|
345
366
|
|
346
367
|
def value_or_descend(data_hash, key, auto_vivifiy=false)
|
347
|
-
|
348
368
|
if auto_vivifiy
|
349
|
-
|
350
|
-
|
351
|
-
current_attribute[key] = data_hash[key]
|
352
|
-
end
|
353
|
-
unless current_default.has_key?(key)
|
354
|
-
current_default[key] = data_hash[key]
|
355
|
-
end
|
356
|
-
unless current_override.has_key?(key)
|
357
|
-
current_override[key] = data_hash[key]
|
358
|
-
end
|
369
|
+
hash_to_vivifiy = auto_vivifiy(data_hash, key)
|
370
|
+
data_hash[key] = hash_to_vivifiy[key]
|
359
371
|
else
|
360
372
|
return nil if data_hash == nil
|
361
373
|
return nil unless data_hash.has_key?(key)
|
362
374
|
end
|
363
375
|
|
364
376
|
if data_hash[key].respond_to?(:has_key?)
|
365
|
-
cna = Chef::Node::Attribute.new(@
|
366
|
-
cna.
|
377
|
+
cna = Chef::Node::Attribute.new(@normal, @default, @override, @automatic, @state)
|
378
|
+
cna.current_normal = current_normal.nil? ? Mash.new : current_normal[key]
|
367
379
|
cna.current_default = current_default.nil? ? Mash.new : current_default[key]
|
368
380
|
cna.current_override = current_override.nil? ? Mash.new : current_override[key]
|
381
|
+
cna.current_automatic = current_automatic.nil? ? Mash.new : current_automatic[key]
|
369
382
|
cna.auto_vivifiy_on_read = auto_vivifiy_on_read
|
370
383
|
cna.set_unless_value_present = set_unless_value_present
|
384
|
+
cna.set_type = set_type
|
371
385
|
cna
|
372
386
|
else
|
373
387
|
data_hash[key]
|
@@ -399,7 +413,7 @@ class Chef
|
|
399
413
|
end
|
400
414
|
|
401
415
|
def to_hash
|
402
|
-
result = determine_value(current_override,
|
416
|
+
result = determine_value(current_automatic, current_override, current_normal, current_default)
|
403
417
|
if result.class == Hash
|
404
418
|
result
|
405
419
|
else
|
data/lib/chef/platform.rb
CHANGED
@@ -129,26 +129,39 @@ class Chef
|
|
129
129
|
},
|
130
130
|
:mswin => {
|
131
131
|
:default => {
|
132
|
-
:
|
132
|
+
:env => Chef::Provider::Env::Windows,
|
133
|
+
:service => Chef::Provider::Service::Windows,
|
134
|
+
:user => Chef::Provider::User::Windows,
|
135
|
+
:group => Chef::Provider::Group::Windows
|
133
136
|
}
|
134
137
|
},
|
135
138
|
:mingw32 => {
|
136
139
|
:default => {
|
137
|
-
:
|
140
|
+
:env => Chef::Provider::Env::Windows,
|
141
|
+
:service => Chef::Provider::Service::Windows,
|
142
|
+
:user => Chef::Provider::User::Windows,
|
143
|
+
:group => Chef::Provider::Group::Windows
|
138
144
|
}
|
139
145
|
},
|
140
146
|
:windows => {
|
141
147
|
:default => {
|
142
|
-
:
|
148
|
+
:env => Chef::Provider::Env::Windows,
|
149
|
+
:service => Chef::Provider::Service::Windows,
|
150
|
+
:user => Chef::Provider::User::Windows,
|
151
|
+
:group => Chef::Provider::Group::Windows
|
143
152
|
}
|
144
153
|
},
|
145
154
|
:solaris => {},
|
155
|
+
:solaris2 => {
|
156
|
+
:default => {
|
157
|
+
:service => Chef::Provider::Service::Solaris
|
158
|
+
}
|
159
|
+
},
|
146
160
|
:default => {
|
147
161
|
:file => Chef::Provider::File,
|
148
162
|
:directory => Chef::Provider::Directory,
|
149
163
|
:link => Chef::Provider::Link,
|
150
164
|
:template => Chef::Provider::Template,
|
151
|
-
:remote_file => Chef::Provider::RemoteFile,
|
152
165
|
:remote_directory => Chef::Provider::RemoteDirectory,
|
153
166
|
:execute => Chef::Provider::Execute,
|
154
167
|
:mount => Chef::Provider::Mount::Mount,
|
@@ -224,7 +237,14 @@ class Chef
|
|
224
237
|
return platform, version
|
225
238
|
end
|
226
239
|
|
240
|
+
def provider_for_resource(resource)
|
241
|
+
node = resource.run_context && resource.run_context.node
|
242
|
+
raise ArgumentError, "Cannot find the provider for a resource with no run context set" unless node
|
243
|
+
find_provider_for_node(node, resource).new(resource, resource.run_context)
|
244
|
+
end
|
245
|
+
|
227
246
|
def provider_for_node(node, resource_type)
|
247
|
+
raise NotImplementedError, "#{self.class.name} no longer supports #provider_for_node"
|
228
248
|
find_provider_for_node(node, resource_type).new(node, resource_type)
|
229
249
|
end
|
230
250
|
|
data/lib/chef/provider.rb
CHANGED
@@ -26,16 +26,25 @@ class Chef
|
|
26
26
|
|
27
27
|
include Chef::Mixin::RecipeDefinitionDSLCore
|
28
28
|
|
29
|
-
attr_accessor :
|
29
|
+
attr_accessor :new_resource, :current_resource, :run_context
|
30
30
|
|
31
|
-
def initialize(
|
32
|
-
@node = node
|
31
|
+
def initialize(new_resource, run_context)
|
33
32
|
@new_resource = new_resource
|
34
33
|
@current_resource = nil
|
35
|
-
@
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
@run_context = run_context
|
35
|
+
end
|
36
|
+
|
37
|
+
def node
|
38
|
+
run_context && run_context.node
|
39
|
+
end
|
40
|
+
|
41
|
+
# Used by providers supporting embedded recipes
|
42
|
+
def resource_collection
|
43
|
+
run_context && run_context.resource_collection
|
44
|
+
end
|
45
|
+
|
46
|
+
def cookbook_name
|
47
|
+
new_resource.cookbook_name
|
39
48
|
end
|
40
49
|
|
41
50
|
def load_current_resource
|
@@ -50,12 +59,21 @@ class Chef
|
|
50
59
|
protected
|
51
60
|
|
52
61
|
def recipe_eval(&block)
|
53
|
-
|
62
|
+
# This block has new resource definitions within it, which
|
63
|
+
# essentially makes it an in-line Chef run. Save our current
|
64
|
+
# run_context and create one anew, so the new Chef run only
|
65
|
+
# executes the embedded resources.
|
66
|
+
#
|
67
|
+
# TODO: timh,cw: 2010-5-14: This means that the resources within
|
68
|
+
# this block cannot interact with resources outside, e.g.,
|
69
|
+
# manipulating notifies.
|
70
|
+
saved_run_context = run_context
|
71
|
+
self.run_context = Chef::RunContext.new(saved_run_context.node, saved_run_context.cookbook_collection)
|
54
72
|
|
55
73
|
instance_eval(&block)
|
56
|
-
Chef::Runner.new(
|
74
|
+
Chef::Runner.new(run_context).converge
|
57
75
|
|
58
|
-
|
76
|
+
self.run_context = saved_run_context
|
59
77
|
end
|
60
78
|
|
61
79
|
public
|
@@ -25,9 +25,9 @@ class Chef
|
|
25
25
|
|
26
26
|
def action_break
|
27
27
|
if defined?(Shef) && Shef.running?
|
28
|
-
|
28
|
+
run_context.resource_collection.iterator.pause
|
29
29
|
@new_resource.updated = true
|
30
|
-
|
30
|
+
run_context.resource_collection.iterator
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -0,0 +1,96 @@
|
|
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/file_access_control'
|
20
|
+
require 'chef/provider/file'
|
21
|
+
require 'tempfile'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class CookbookFile < Chef::Provider::File
|
26
|
+
|
27
|
+
def load_current_resource
|
28
|
+
@current_resource = Chef::Resource::CookbookFile.new(@new_resource.name)
|
29
|
+
@new_resource.path.gsub!(/\\/, "/") # for Windows
|
30
|
+
@current_resource.path(@new_resource.path)
|
31
|
+
@current_resource
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def action_create
|
36
|
+
if file_cache_location
|
37
|
+
Chef::Log.debug("content of file #{@new_resource.path} requires update")
|
38
|
+
backup_new_resource
|
39
|
+
Tempfile.open(::File.basename(@new_resource.name)) do |staging_file|
|
40
|
+
Chef::Log.debug("staging #{file_cache_location} to #{staging_file.path}")
|
41
|
+
staging_file.close
|
42
|
+
stage_file_to_tmpdir(staging_file.path)
|
43
|
+
FileUtils.mv(staging_file.path, @new_resource.path)
|
44
|
+
end
|
45
|
+
@new_resource.updated = true
|
46
|
+
else
|
47
|
+
set_all_access_controls(@new_resource.path)
|
48
|
+
end
|
49
|
+
@new_resource.updated
|
50
|
+
end
|
51
|
+
|
52
|
+
def action_create_if_missing
|
53
|
+
if ::File.exists?(@new_resource.path)
|
54
|
+
Chef::Log.debug("File #{@new_resource.path} exists, taking no action.")
|
55
|
+
else
|
56
|
+
action_create
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def file_cache_location
|
61
|
+
@file_cache_location ||= begin
|
62
|
+
cookbook = run_context.cookbook_collection[resource_cookbook]
|
63
|
+
cookbook.preferred_filename_on_disk_location(node, :files, @new_resource.source, @new_resource.path)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Determine the cookbook to get the file from. If new resource sets an
|
68
|
+
# explicit cookbook, use it, otherwise fall back to the implicit cookbook
|
69
|
+
# i.e., the cookbook the resource was declared in.
|
70
|
+
def resource_cookbook
|
71
|
+
@new_resource.cookbook || @new_resource.cookbook_name
|
72
|
+
end
|
73
|
+
|
74
|
+
# Copy the file from the cookbook cache to a temporary location and then
|
75
|
+
# set its file access control settings.
|
76
|
+
def stage_file_to_tmpdir(staging_file_location)
|
77
|
+
FileUtils.cp(file_cache_location, staging_file_location)
|
78
|
+
set_all_access_controls(staging_file_location)
|
79
|
+
end
|
80
|
+
|
81
|
+
def set_all_access_controls(file)
|
82
|
+
access_controls = Chef::FileAccessControl.new(@new_resource, file)
|
83
|
+
access_controls.set_all
|
84
|
+
@new_resource.updated = access_controls.modified?
|
85
|
+
end
|
86
|
+
|
87
|
+
def backup_new_resource
|
88
|
+
if ::File.exists?(@new_resource.path)
|
89
|
+
Chef::Log.info "Backing up current file at #{@new_resource.path}"
|
90
|
+
backup @new_resource.path
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|