summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/guard_interpreter/resource_guard_interpreter.rb1
-rw-r--r--lib/chef/mixin/why_run.rb2
-rw-r--r--lib/chef/resource/execute.rb7
3 files changed, 9 insertions, 1 deletions
diff --git a/lib/chef/guard_interpreter/resource_guard_interpreter.rb b/lib/chef/guard_interpreter/resource_guard_interpreter.rb
index 346b585d8c..7d9bccb6ca 100644
--- a/lib/chef/guard_interpreter/resource_guard_interpreter.rb
+++ b/lib/chef/guard_interpreter/resource_guard_interpreter.rb
@@ -95,6 +95,7 @@ class Chef
empty_events = Chef::EventDispatch::Dispatcher.new
anonymous_run_context = Chef::RunContext.new(parent_resource.node, {}, empty_events)
interpreter_resource = resource_class.new('Guard resource', anonymous_run_context)
+ interpreter_resource.is_guard_interpreter = true
interpreter_resource
end
diff --git a/lib/chef/mixin/why_run.rb b/lib/chef/mixin/why_run.rb
index d650e3332f..d3acea5490 100644
--- a/lib/chef/mixin/why_run.rb
+++ b/lib/chef/mixin/why_run.rb
@@ -48,7 +48,7 @@ class Chef
# block/proc that implements the action.
def add_action(descriptions, &block)
@actions << [descriptions, block]
- if !Chef::Config[:why_run]
+ if (@resource.respond_to?(:is_guard_interpreter) && @resource.is_guard_interpreter) || !Chef::Config[:why_run]
block.call
end
events.resource_update_applied(@resource, @action, descriptions)
diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb
index 6853b62887..9f8b629fb8 100644
--- a/lib/chef/resource/execute.rb
+++ b/lib/chef/resource/execute.rb
@@ -26,6 +26,12 @@ class Chef
identity_attr :command
+ # The ResourceGuardInterpreter wraps a resource's guards in another resource. That inner resource
+ # needs to behave differently during (for example) why_run mode, so we flag it here. For why_run mode
+ # we still want to execute the guard resource even if we are not executing the wrapping resource.
+ # Only execute resources (and subclasses) can be guard interpreters.
+ attr_accessor :is_guard_interpreter
+
def initialize(name, run_context=nil)
super
@resource_name = :execute
@@ -43,6 +49,7 @@ class Chef
@allowed_actions.push(:run)
@umask = nil
@default_guard_interpreter = :execute
+ @is_guard_interpreter = false
end
def umask(arg=nil)