summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Dibowitz <phil@ipom.com>2013-11-06 11:01:27 -0800
committerPhil Dibowitz <phil@ipom.com>2013-11-21 12:56:51 -0800
commit843f5e91668df5f42f56937cd84549301b839165 (patch)
treeed31453d93573221c8856b00c21484da89be1fb7
parent06c0b8b13b326871710d4233b0cbc36744c57f79 (diff)
downloadchef-843f5e91668df5f42f56937cd84549301b839165.tar.gz
[CHEF-4110] Add a "whyrun_safe" attribute to ruby_block
10-stable edition
-rw-r--r--chef/lib/chef/provider/ruby_block.rb13
-rw-r--r--chef/lib/chef/resource/ruby_block.rb10
2 files changed, 21 insertions, 2 deletions
diff --git a/chef/lib/chef/provider/ruby_block.rb b/chef/lib/chef/provider/ruby_block.rb
index e5e5d01152..1924e2f83b 100644
--- a/chef/lib/chef/provider/ruby_block.rb
+++ b/chef/lib/chef/provider/ruby_block.rb
@@ -29,9 +29,18 @@ class Chef
end
def action_create
- converge_by("execute the ruby block #{@new_resource.name}") do
+ if @new_resource.whyrun_safe
@new_resource.block.call
- Chef::Log.info("#{@new_resource} called")
+ if Chef::Config[:why_run]
+ Chef::Log.info("#{@new_resource} called - labelled as whyrun-safe")
+ else
+ Chef::Log.info("#{@new_resource} called")
+ end
+ else
+ converge_by("execute the ruby block #{@new_resource.name}") do
+ @new_resource.block.call
+ Chef::Log.info("#{@new_resource} called")
+ end
end
end
end
diff --git a/chef/lib/chef/resource/ruby_block.rb b/chef/lib/chef/resource/ruby_block.rb
index cb743819aa..edabe43e59 100644
--- a/chef/lib/chef/resource/ruby_block.rb
+++ b/chef/lib/chef/resource/ruby_block.rb
@@ -22,6 +22,7 @@ class Chef
class RubyBlock < Chef::Resource
identity_attr :block_name
+ state_attrs :whyrun_safe
def initialize(name, run_context=nil)
super
@@ -29,6 +30,7 @@ class Chef
@action = "create"
@allowed_actions.push(:create)
@block_name = name
+ @whyrun_safe = false
end
def block(&block)
@@ -46,6 +48,14 @@ class Chef
:kind_of => String
)
end
+
+ def whyrun_safe(arg=nil)
+ set_or_return(
+ :whyrun_safe,
+ arg,
+ :kind_of => [ TrueClass, FalseClass ]
+ )
+ end
end
end
end