giraffesoft-chef 0.7.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +135 -0
  3. data/bin/chef-client +26 -0
  4. data/bin/chef-solo +26 -0
  5. data/distro/debian/etc/init.d/chef-client +175 -0
  6. data/distro/debian/etc/init.d/chef-indexer +175 -0
  7. data/distro/debian/etc/init.d/chef-server +120 -0
  8. data/distro/debian/man/man1/chef-indexer.1 +42 -0
  9. data/distro/debian/man/man1/chef-server.1 +108 -0
  10. data/distro/debian/man/man8/chef-client.8 +61 -0
  11. data/distro/debian/man/man8/chef-solo.8 +58 -0
  12. data/distro/redhat/etc/chef/client.rb +16 -0
  13. data/distro/redhat/etc/chef/indexer.rb +10 -0
  14. data/distro/redhat/etc/chef/server.rb +22 -0
  15. data/distro/redhat/etc/init.d/chef-client +74 -0
  16. data/distro/redhat/etc/init.d/chef-indexer +76 -0
  17. data/distro/redhat/etc/init.d/chef-server +77 -0
  18. data/lib/chef.rb +49 -0
  19. data/lib/chef/application.rb +98 -0
  20. data/lib/chef/application/agent.rb +18 -0
  21. data/lib/chef/application/client.rb +209 -0
  22. data/lib/chef/application/indexer.rb +141 -0
  23. data/lib/chef/application/server.rb +18 -0
  24. data/lib/chef/application/solo.rb +214 -0
  25. data/lib/chef/client.rb +421 -0
  26. data/lib/chef/compile.rb +170 -0
  27. data/lib/chef/config.rb +141 -0
  28. data/lib/chef/cookbook.rb +171 -0
  29. data/lib/chef/cookbook/metadata.rb +407 -0
  30. data/lib/chef/cookbook/metadata/version.rb +87 -0
  31. data/lib/chef/cookbook_loader.rb +180 -0
  32. data/lib/chef/couchdb.rb +176 -0
  33. data/lib/chef/daemon.rb +170 -0
  34. data/lib/chef/exceptions.rb +36 -0
  35. data/lib/chef/file_cache.rb +205 -0
  36. data/lib/chef/log.rb +39 -0
  37. data/lib/chef/mixin/check_helper.rb +31 -0
  38. data/lib/chef/mixin/checksum.rb +37 -0
  39. data/lib/chef/mixin/command.rb +386 -0
  40. data/lib/chef/mixin/convert_to_class_name.rb +48 -0
  41. data/lib/chef/mixin/create_path.rb +56 -0
  42. data/lib/chef/mixin/deep_merge.rb +36 -0
  43. data/lib/chef/mixin/find_preferred_file.rb +92 -0
  44. data/lib/chef/mixin/from_file.rb +50 -0
  45. data/lib/chef/mixin/generate_url.rb +49 -0
  46. data/lib/chef/mixin/language.rb +79 -0
  47. data/lib/chef/mixin/params_validate.rb +197 -0
  48. data/lib/chef/mixin/recipe_definition_dsl_core.rb +77 -0
  49. data/lib/chef/mixin/template.rb +84 -0
  50. data/lib/chef/node.rb +406 -0
  51. data/lib/chef/node/attribute.rb +412 -0
  52. data/lib/chef/openid_registration.rb +181 -0
  53. data/lib/chef/platform.rb +254 -0
  54. data/lib/chef/provider.rb +101 -0
  55. data/lib/chef/provider/cron.rb +187 -0
  56. data/lib/chef/provider/deploy.rb +281 -0
  57. data/lib/chef/provider/deploy/revision.rb +70 -0
  58. data/lib/chef/provider/deploy/timestamped.rb +33 -0
  59. data/lib/chef/provider/directory.rb +72 -0
  60. data/lib/chef/provider/execute.rb +58 -0
  61. data/lib/chef/provider/file.rb +191 -0
  62. data/lib/chef/provider/git.rb +198 -0
  63. data/lib/chef/provider/group.rb +120 -0
  64. data/lib/chef/provider/group/gpasswd.rb +50 -0
  65. data/lib/chef/provider/group/groupadd.rb +78 -0
  66. data/lib/chef/provider/group/pw.rb +88 -0
  67. data/lib/chef/provider/group/usermod.rb +57 -0
  68. data/lib/chef/provider/http_request.rb +102 -0
  69. data/lib/chef/provider/ifconfig.rb +131 -0
  70. data/lib/chef/provider/link.rb +157 -0
  71. data/lib/chef/provider/mount.rb +117 -0
  72. data/lib/chef/provider/mount/mount.rb +208 -0
  73. data/lib/chef/provider/package.rb +160 -0
  74. data/lib/chef/provider/package/apt.rb +110 -0
  75. data/lib/chef/provider/package/dpkg.rb +109 -0
  76. data/lib/chef/provider/package/freebsd.rb +153 -0
  77. data/lib/chef/provider/package/macports.rb +105 -0
  78. data/lib/chef/provider/package/portage.rb +124 -0
  79. data/lib/chef/provider/package/rpm.rb +99 -0
  80. data/lib/chef/provider/package/rubygems.rb +136 -0
  81. data/lib/chef/provider/package/yum-dump.py +106 -0
  82. data/lib/chef/provider/package/yum.rb +175 -0
  83. data/lib/chef/provider/remote_directory.rb +126 -0
  84. data/lib/chef/provider/remote_file.rb +141 -0
  85. data/lib/chef/provider/route.rb +118 -0
  86. data/lib/chef/provider/ruby_block.rb +15 -0
  87. data/lib/chef/provider/script.rb +42 -0
  88. data/lib/chef/provider/service.rb +135 -0
  89. data/lib/chef/provider/service/debian.rb +64 -0
  90. data/lib/chef/provider/service/freebsd.rb +157 -0
  91. data/lib/chef/provider/service/gentoo.rb +54 -0
  92. data/lib/chef/provider/service/init.rb +71 -0
  93. data/lib/chef/provider/service/redhat.rb +62 -0
  94. data/lib/chef/provider/service/simple.rb +115 -0
  95. data/lib/chef/provider/subversion.rb +148 -0
  96. data/lib/chef/provider/template.rb +143 -0
  97. data/lib/chef/provider/user.rb +170 -0
  98. data/lib/chef/provider/user/pw.rb +113 -0
  99. data/lib/chef/provider/user/useradd.rb +107 -0
  100. data/lib/chef/queue.rb +145 -0
  101. data/lib/chef/recipe.rb +144 -0
  102. data/lib/chef/resource.rb +380 -0
  103. data/lib/chef/resource/apt_package.rb +34 -0
  104. data/lib/chef/resource/bash.rb +33 -0
  105. data/lib/chef/resource/cron.rb +179 -0
  106. data/lib/chef/resource/csh.rb +33 -0
  107. data/lib/chef/resource/deploy.rb +350 -0
  108. data/lib/chef/resource/deploy_revision.rb +35 -0
  109. data/lib/chef/resource/directory.rb +76 -0
  110. data/lib/chef/resource/dpkg_package.rb +34 -0
  111. data/lib/chef/resource/execute.rb +127 -0
  112. data/lib/chef/resource/file.rb +84 -0
  113. data/lib/chef/resource/gem_package.rb +41 -0
  114. data/lib/chef/resource/git.rb +36 -0
  115. data/lib/chef/resource/group.rb +70 -0
  116. data/lib/chef/resource/http_request.rb +52 -0
  117. data/lib/chef/resource/ifconfig.rb +134 -0
  118. data/lib/chef/resource/link.rb +78 -0
  119. data/lib/chef/resource/macports_package.rb +29 -0
  120. data/lib/chef/resource/mount.rb +135 -0
  121. data/lib/chef/resource/package.rb +80 -0
  122. data/lib/chef/resource/perl.rb +33 -0
  123. data/lib/chef/resource/portage_package.rb +33 -0
  124. data/lib/chef/resource/python.rb +33 -0
  125. data/lib/chef/resource/remote_directory.rb +91 -0
  126. data/lib/chef/resource/remote_file.rb +60 -0
  127. data/lib/chef/resource/route.rb +135 -0
  128. data/lib/chef/resource/ruby.rb +33 -0
  129. data/lib/chef/resource/ruby_block.rb +20 -0
  130. data/lib/chef/resource/scm.rb +129 -0
  131. data/lib/chef/resource/script.rb +51 -0
  132. data/lib/chef/resource/service.rb +134 -0
  133. data/lib/chef/resource/subversion.rb +33 -0
  134. data/lib/chef/resource/template.rb +60 -0
  135. data/lib/chef/resource/timestamped_deploy.rb +31 -0
  136. data/lib/chef/resource/user.rb +98 -0
  137. data/lib/chef/resource_collection.rb +204 -0
  138. data/lib/chef/resource_definition.rb +67 -0
  139. data/lib/chef/rest.rb +238 -0
  140. data/lib/chef/role.rb +231 -0
  141. data/lib/chef/run_list.rb +156 -0
  142. data/lib/chef/runner.rb +130 -0
  143. data/lib/chef/search.rb +88 -0
  144. data/lib/chef/search/result.rb +64 -0
  145. data/lib/chef/search_index.rb +77 -0
  146. data/lib/chef/tasks/chef_repo.rake +347 -0
  147. data/lib/chef/util/file_edit.rb +125 -0
  148. data/lib/chef/util/fileedit.rb +121 -0
  149. metadata +293 -0
data/lib/chef/role.rb ADDED
@@ -0,0 +1,231 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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/config'
20
+ require 'chef/mixin/params_validate'
21
+ require 'chef/mixin/from_file'
22
+ require 'chef/couchdb'
23
+ require 'extlib'
24
+ require 'json'
25
+
26
+ class Chef
27
+ class Role
28
+
29
+ include Chef::Mixin::FromFile
30
+ include Chef::Mixin::ParamsValidate
31
+
32
+ DESIGN_DOCUMENT = {
33
+ "version" => 3,
34
+ "language" => "javascript",
35
+ "views" => {
36
+ "all" => {
37
+ "map" => <<-EOJS
38
+ function(doc) {
39
+ if (doc.chef_type == "role") {
40
+ emit(doc.name, doc);
41
+ }
42
+ }
43
+ EOJS
44
+ },
45
+ "all_id" => {
46
+ "map" => <<-EOJS
47
+ function(doc) {
48
+ if (doc.chef_type == "role") {
49
+ emit(doc.name, doc.name);
50
+ }
51
+ }
52
+ EOJS
53
+ },
54
+ },
55
+ }
56
+
57
+ attr_accessor :couchdb_rev
58
+
59
+ # Create a new Chef::Role object.
60
+ def initialize()
61
+ @name = ''
62
+ @description = ''
63
+ @default_attributes = Mash.new
64
+ @override_attributes = Mash.new
65
+ @recipes = Array.new
66
+ @couchdb_rev = nil
67
+ @couchdb = Chef::CouchDB.new
68
+ end
69
+
70
+ def name(arg=nil)
71
+ set_or_return(
72
+ :name,
73
+ arg,
74
+ :regex => /^[\-[:alnum:]_]+$/
75
+ )
76
+ end
77
+
78
+ def description(arg=nil)
79
+ set_or_return(
80
+ :description,
81
+ arg,
82
+ :kind_of => String
83
+ )
84
+ end
85
+
86
+ def recipes(*arg)
87
+ arg.flatten!
88
+ if arg.length == 0
89
+ @recipes
90
+ else
91
+ arg.each do |entry|
92
+ raise ArgumentError, 'Recipes must be strings!' unless entry.kind_of?(String)
93
+ end
94
+ @recipes = arg
95
+ end
96
+ end
97
+
98
+ def default_attributes(arg=nil)
99
+ set_or_return(
100
+ :default_attributes,
101
+ arg,
102
+ :kind_of => Hash
103
+ )
104
+ end
105
+
106
+ def override_attributes(arg=nil)
107
+ set_or_return(
108
+ :override_attributes,
109
+ arg,
110
+ :kind_of => Hash
111
+ )
112
+ end
113
+
114
+ def to_hash
115
+ result = {
116
+ "name" => @name,
117
+ "description" => @description,
118
+ 'json_class' => self.class.name,
119
+ "default_attributes" => @default_attributes,
120
+ "override_attributes" => @override_attributes,
121
+ "chef_type" => "role",
122
+ "recipes" => @recipes,
123
+ }
124
+ result["_rev"] = @couchdb_rev if @couchdb_rev
125
+ result
126
+ end
127
+
128
+ # Serialize this object as a hash
129
+ def to_json(*a)
130
+ to_hash.to_json(*a)
131
+ end
132
+
133
+ # Create a Chef::Role from JSON
134
+ def self.json_create(o)
135
+ role = new
136
+ role.name(o["name"])
137
+ role.description(o["description"])
138
+ role.default_attributes(o["default_attributes"])
139
+ role.override_attributes(o["override_attributes"])
140
+ role.recipes(o["recipes"])
141
+ role.couchdb_rev = o["_rev"] if o.has_key?("_rev")
142
+ role
143
+ end
144
+
145
+ # List all the Chef::Role objects in the CouchDB. If inflate is set to true, you will get
146
+ # the full list of all Roles, fully inflated.
147
+ def self.list(inflate=false)
148
+ rs = Chef::CouchDB.new.list("roles", inflate)
149
+ if inflate
150
+ rs["rows"].collect { |r| r["value"] }
151
+ else
152
+ rs["rows"].collect { |r| r["key"] }
153
+ end
154
+ end
155
+
156
+ # Load a role by name from CouchDB
157
+ def self.load(name)
158
+ Chef::CouchDB.new.load("role", name)
159
+ end
160
+
161
+ # Remove this role from the CouchDB
162
+ def destroy
163
+ @couchdb.delete("role", @name, @couchdb_rev)
164
+
165
+ if Chef::Config[:couchdb_version] == 0.9
166
+ rs = @couchdb.get_view("nodes", "by_run_list", :startkey => "role[#{@name}]", :endkey => "role[#{@name}]", :include_docs => true)
167
+ rs["rows"].each do |row|
168
+ node = row["doc"]
169
+ node.run_list.remove("role[#{@name}]")
170
+ node.save
171
+ end
172
+ else
173
+ Chef::Node.list.each do |node|
174
+ n = Chef::Node.load(node)
175
+ n.run_list.remove("role[#{@name}]")
176
+ n.save
177
+ end
178
+ end
179
+ end
180
+
181
+ # Save this role to the CouchDB
182
+ def save
183
+ results = @couchdb.store("role", @name, self)
184
+ @couchdb_rev = results["rev"]
185
+ end
186
+
187
+ # Set up our CouchDB design document
188
+ def self.create_design_document
189
+ Chef::CouchDB.new.create_design_document("roles", DESIGN_DOCUMENT)
190
+ end
191
+
192
+ # As a string
193
+ def to_s
194
+ "role[#{@name}]"
195
+ end
196
+
197
+ # Load a role from disk - prefers to load the JSON, but will happily load
198
+ # the raw rb files as well.
199
+ def self.from_disk(name, force=nil)
200
+ js_file = File.join(Chef::Config[:role_path], "#{name}.json")
201
+ rb_file = File.join(Chef::Config[:role_path], "#{name}.rb")
202
+
203
+ if File.exists?(js_file) || force == "json"
204
+ JSON.parse(IO.read(js_file))
205
+ elsif File.exists?(rb_file) || force == "ruby"
206
+ role = Chef::Role.new
207
+ role.name(name)
208
+ role.from_file(rb_file)
209
+ role
210
+ end
211
+ end
212
+
213
+ # Sync all the json roles with couchdb from disk
214
+ def self.sync_from_disk_to_couchdb
215
+ Dir[File.join(Chef::Config[:role_path], "*.json")].each do |role_file|
216
+ short_name = File.basename(role_file, ".json")
217
+ Chef::Log.warn("Loading #{short_name}")
218
+ r = Chef::Role.from_disk(short_name, "json")
219
+ begin
220
+ couch_role = Chef::Role.load(short_name)
221
+ r.couchdb_rev = couch_role.couchdb_rev
222
+ Chef::Log.debug("Replacing role #{short_name} with data from #{role_file}")
223
+ rescue Net::HTTPServerException
224
+ Chef::Log.debug("Creating role #{short_name} with data from #{role_file}")
225
+ end
226
+ r.save
227
+ end
228
+ end
229
+
230
+ end
231
+ end
@@ -0,0 +1,156 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008, 2009 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
+ require 'chef/mixin/deep_merge'
19
+
20
+ class Chef
21
+ class RunList
22
+ include Enumerable
23
+
24
+ attr_reader :recipes, :roles, :run_list
25
+
26
+ def initialize
27
+ @run_list = Array.new
28
+ @recipes = Array.new
29
+ @roles = Array.new
30
+ end
31
+
32
+ def <<(item)
33
+ type, entry, fentry = parse_entry(item)
34
+ case type
35
+ when 'recipe'
36
+ @recipes << entry unless @recipes.include?(entry)
37
+ when 'role'
38
+ @roles << entry unless @roles.include?(entry)
39
+ end
40
+ @run_list << fentry unless @run_list.include?(fentry)
41
+ self
42
+ end
43
+
44
+ def ==(*isequal)
45
+ check_array = nil
46
+ if isequal[0].kind_of?(Chef::RunList)
47
+ check_array = isequal[0].run_list
48
+ else
49
+ check_array = isequal.flatten
50
+ end
51
+
52
+ return false if check_array.length != @run_list.length
53
+
54
+ check_array.each_index do |i|
55
+ to_check = check_array[i]
56
+ type, name, fname = parse_entry(to_check)
57
+ return false if @run_list[i] != fname
58
+ end
59
+
60
+ true
61
+ end
62
+
63
+ def empty?
64
+ @run_list.length == 0 ? true : false
65
+ end
66
+
67
+ def [](pos)
68
+ @run_list[pos]
69
+ end
70
+
71
+ def []=(pos, item)
72
+ type, entry, fentry = parse_entry(item)
73
+ @run_list[pos] = fentry
74
+ end
75
+
76
+ def each(&block)
77
+ @run_list.each { |i| block.call(i) }
78
+ end
79
+
80
+ def each_index(&block)
81
+ @run_list.each_index { |i| block.call(i) }
82
+ end
83
+
84
+ def include?(item)
85
+ type, entry, fentry = parse_entry(item)
86
+ @run_list.include?(fentry)
87
+ end
88
+
89
+ def reset(*args)
90
+ @run_list = Array.new
91
+ @recipes = Array.new
92
+ @roles = Array.new
93
+ args.flatten.each do |item|
94
+ if item.kind_of?(Chef::RunList)
95
+ item.each { |r| self << r }
96
+ else
97
+ self << item
98
+ end
99
+ end
100
+ self
101
+ end
102
+
103
+ def remove(item)
104
+ type, entry, fentry = parse_entry(item)
105
+ @run_list.delete_if { |i| i == fentry }
106
+ if type == "recipe"
107
+ @recipes.delete_if { |i| i == entry }
108
+ elsif type == "role"
109
+ @roles.delete_if { |i| i == entry }
110
+ end
111
+ self
112
+ end
113
+
114
+ def expand(from='server')
115
+ recipes = Array.new
116
+ default_attrs = Mash.new
117
+ override_attrs = Mash.new
118
+
119
+ @run_list.each do |entry|
120
+ type, name, fname = parse_entry(entry)
121
+ case type
122
+ when 'recipe'
123
+ recipes << name unless recipes.include?(name)
124
+ when 'role'
125
+ role = nil
126
+ if from == 'disk' || Chef::Config[:solo]
127
+ # Load the role from disk
128
+ role = Chef::Role.from_disk("#{name}")
129
+ elsif from == 'server'
130
+ # Load the role from the server
131
+ r = Chef::REST.new(Chef::Config[:role_url])
132
+ role = r.get_rest("roles/#{name}")
133
+ elsif from == 'couchdb'
134
+ # Load the role from couchdb
135
+ role = Chef::Role.load(name)
136
+ end
137
+ role.recipes.each { |r| recipes << r unless recipes.include?(r) }
138
+ default_attrs = Chef::Mixin::DeepMerge.merge(default_attrs, role.default_attributes)
139
+ override_attrs = Chef::Mixin::DeepMerge.merge(override_attrs, role.override_attributes)
140
+ end
141
+ end
142
+ return recipes, default_attrs, override_attrs
143
+ end
144
+
145
+ def parse_entry(entry)
146
+ case entry
147
+ when /^(.+)\[(.+)\]$/
148
+ [ $1, $2, entry ]
149
+ else
150
+ [ 'recipe', entry, "recipe[#{entry}]" ]
151
+ end
152
+ end
153
+
154
+ end
155
+ end
156
+
@@ -0,0 +1,130 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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/mixin/params_validate'
20
+ require 'chef/node'
21
+ require 'chef/resource_collection'
22
+ require 'chef/platform'
23
+
24
+ class Chef
25
+ class Runner
26
+
27
+ include Chef::Mixin::ParamsValidate
28
+
29
+ def initialize(node, collection, definitions={}, cookbook_loader=nil)
30
+ validate(
31
+ {
32
+ :node => node,
33
+ :collection => collection,
34
+ },
35
+ {
36
+ :node => {
37
+ :kind_of => Chef::Node,
38
+ },
39
+ :collection => {
40
+ :kind_of => Chef::ResourceCollection,
41
+ },
42
+ }
43
+ )
44
+ @node = node
45
+ @collection = collection
46
+ @definitions = definitions
47
+ @cookbook_loader = cookbook_loader
48
+ end
49
+
50
+ def build_provider(resource)
51
+ provider_klass = resource.provider
52
+ provider_klass ||= Chef::Platform.find_provider_for_node(@node, resource)
53
+ Chef::Log.debug("#{resource} using #{provider_klass.to_s}")
54
+ provider = provider_klass.new(@node, resource, @collection, @definitions, @cookbook_loader)
55
+ provider.load_current_resource
56
+ provider
57
+ end
58
+
59
+ def run_action(resource, ra)
60
+ provider = build_provider(resource)
61
+ provider.send("action_#{ra}")
62
+
63
+ if resource.updated
64
+ resource.actions.each_key do |action|
65
+ if resource.actions[action].has_key?(:immediate)
66
+ resource.actions[action][:immediate].each do |r|
67
+ Chef::Log.info("#{resource} sending #{action} action to #{r} (immediate)")
68
+ run_action(r, action)
69
+ end
70
+ end
71
+ if resource.actions[action].has_key?(:delayed)
72
+ resource.actions[action][:delayed].each do |r|
73
+ @delayed_actions[r] = Hash.new unless @delayed_actions.has_key?(r)
74
+ @delayed_actions[r][action] = Array.new unless @delayed_actions[r].has_key?(action)
75
+ @delayed_actions[r][action] << lambda {
76
+ Chef::Log.info("#{resource} sending #{action} action to #{r} (delayed)")
77
+ }
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def converge
85
+
86
+ @delayed_actions = Hash.new
87
+
88
+ @collection.execute_each_resource do |resource|
89
+ begin
90
+ Chef::Log.debug("Processing #{resource}")
91
+
92
+ # Check if this resource has an only_if block - if it does, skip it.
93
+ if resource.only_if
94
+ unless Chef::Mixin::Command.only_if(resource.only_if)
95
+ Chef::Log.debug("Skipping #{resource} due to only_if")
96
+ next
97
+ end
98
+ end
99
+
100
+ # Check if this resource has a not_if block - if it does, skip it.
101
+ if resource.not_if
102
+ unless Chef::Mixin::Command.not_if(resource.not_if)
103
+ Chef::Log.debug("Skipping #{resource} due to not_if")
104
+ next
105
+ end
106
+ end
107
+
108
+ # Walk the actions for this resource, building the provider and running each.
109
+ action_list = resource.action.kind_of?(Array) ? resource.action : [ resource.action ]
110
+ action_list.each do |ra|
111
+ run_action(resource, ra)
112
+ end
113
+ rescue => e
114
+ Chef::Log.error("#{resource} (#{resource.source_line}) had an error:\n#{e}\n#{e.backtrace}")
115
+ raise e unless resource.ignore_failure
116
+ end
117
+ end
118
+
119
+ # Run all our :delayed actions
120
+ @delayed_actions.each do |resource, action_hash|
121
+ action_hash.each do |action, log_array|
122
+ log_array.each { |l| l.call } # Call each log message
123
+ run_action(resource, action)
124
+ end
125
+ end
126
+
127
+ true
128
+ end
129
+ end
130
+ end