summaryrefslogtreecommitdiff
path: root/lib/chef/guard_interpreter
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-10-13 15:57:56 -0700
committerSerdar Sutay <serdar@opscode.com>2014-10-16 13:30:23 -0700
commit8dd586b1fdbb13705a1a3a5f7f792568cc39e434 (patch)
tree19ac34de330ce11140655c6394f2d1a1604322bc /lib/chef/guard_interpreter
parent28fd0c9c87c6fceb7068776a04c32cd8381fe8f6 (diff)
downloadchef-8dd586b1fdbb13705a1a3a5f7f792568cc39e434.tar.gz
Enable guard_interpreters for the execute resource and set the default interpreter for the execute resource to be :execute.
This ensures that attributes of the resource like :environment & :cwd can be inherited by the guard when guard is specified as a string.
Diffstat (limited to 'lib/chef/guard_interpreter')
-rw-r--r--lib/chef/guard_interpreter/resource_guard_interpreter.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/chef/guard_interpreter/resource_guard_interpreter.rb b/lib/chef/guard_interpreter/resource_guard_interpreter.rb
index 229a8502c7..8eaa82c0a5 100644
--- a/lib/chef/guard_interpreter/resource_guard_interpreter.rb
+++ b/lib/chef/guard_interpreter/resource_guard_interpreter.rb
@@ -33,10 +33,19 @@ class Chef
# to the resource
merge_inherited_attributes
- # Script resources have a code attribute, which is
- # what is used to execute the command, so include
- # that with attributes specified by caller in opts
- block_attributes = @command_opts.merge({:code => @command})
+ # Only execute and script resources and use guard attributes.
+ # The command to be executed on them are passed via different attributes.
+ # Script resources use code attribute and execute resources use
+ # command attribute. Moreover script resources are also execute
+ # resources. Here we make sure @command is assigned to the right
+ # attribute by checking the type of the resources.
+ # We need to make sure we check for Script first because any resource
+ # that can get to here is an Execute resource.
+ if @parent_resource.is_a? Chef::Resource::Script
+ block_attributes = @command_opts.merge({:code => @command})
+ else
+ block_attributes = @command_opts.merge({:command => @command})
+ end
# Handles cases like powershell_script where default
# attributes are different when used in a guard vs. not. For
@@ -79,7 +88,7 @@ class Chef
raise ArgumentError, "Specified guard_interpreter resource #{parent_resource.guard_interpreter.to_s} unknown for this platform"
end
- if ! resource_class.ancestors.include?(Chef::Resource::Script)
+ if ! resource_class.ancestors.include?(Chef::Resource::Execute)
raise ArgumentError, "Specified guard interpreter class #{resource_class} must be a kind of Chef::Resource::Script resource"
end