Class: Chef::Provider::Script

Inherits:
Execute show all
Defined in:
lib/chef/provider/script.rb

Constant Summary

Constants included from Mixin::ShellOut

Mixin::ShellOut::DEPRECATED_OPTIONS

Instance Attribute Summary

Attributes inherited from Chef::Provider

#action, #current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods inherited from Execute

#load_current_resource, #whyrun_supported?

Methods included from Mixin::ShellOut

#run_command_compatible_options, #shell_out, #shell_out!

Methods inherited from Chef::Provider

#action_nothing, #cleanup_after_converge, #cookbook_name, #define_resource_requirements, #events, #initialize, #load_current_resource, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #set_updated_status, #whyrun_mode?, #whyrun_supported?

Methods included from DSL::Recipe

#method_missing

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Constructor Details

This class inherits a constructor from Chef::Provider

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::DSL::Recipe

Instance Method Details

#action_runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chef/provider/script.rb', line 26

def action_run
  script_file.puts(@new_resource.code)
  script_file.close

  set_owner_and_group

  @new_resource.command("\"#{@new_resource.interpreter}\" #{@new_resource.flags} \"#{script_file.path}\"")
  super
  converge_by(nil) do
    # ensure script is unlinked at end of converge!
    unlink_script_file
  end
end

#script_fileObject



47
48
49
# File 'lib/chef/provider/script.rb', line 47

def script_file
  @script_file ||= Tempfile.open("chef-script")
end

#set_owner_and_groupObject



40
41
42
43
44
45
# File 'lib/chef/provider/script.rb', line 40

def set_owner_and_group
  # FileUtils itself implements a no-op if +user+ or +group+ are nil
  # You can prove this by running FileUtils.chown(nil,nil,'/tmp/file')
  # as an unprivileged user.
  FileUtils.chown(@new_resource.user, @new_resource.group, script_file.path)
end


51
52
53
# File 'lib/chef/provider/script.rb', line 51

def unlink_script_file
  @script_file && @script_file.close!
end