Class: Chef::Provider::Script
- Inherits:
-
Execute
- Object
- Chef::Provider
- Execute
- Chef::Provider::Script
- Defined in:
- lib/chef/provider/script.rb
Direct Known Subclasses
Constant Summary
Constants included from Mixin::ShellOut
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Attribute Summary
Attributes inherited from Chef::Provider
#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #run_context
Instance Method Summary collapse
- #action_run ⇒ Object
- #flags ⇒ Object
-
#initialize(new_resource, run_context) ⇒ Script
constructor
A new instance of Script.
- #interpreter ⇒ Object
- #script_file ⇒ Object
- #set_owner_and_group ⇒ Object
- #unlink_script_file ⇒ Object
Methods inherited from Execute
#load_current_resource, #whyrun_supported?
Methods inherited from Chef::Provider
#action_nothing, #cleanup_after_converge, #converge_by, #define_resource_requirements, #events, #load_current_resource, #node, node_map, #process_resource_requirements, provides, provides?, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, supports?, #whyrun_mode?, #whyrun_supported?
Methods included from Mixin::DescendantsTracker
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
Methods included from Mixin::ShellOut
#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
Constructor Details
#initialize(new_resource, run_context) ⇒ Script
32 33 34 35 |
# File 'lib/chef/provider/script.rb', line 32 def initialize(new_resource, run_context) super @code = @new_resource.code end |
Instance Method Details
#action_run ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/chef/provider/script.rb', line 37 def action_run script_file.puts(@code) script_file.close set_owner_and_group @new_resource.command("\"#{interpreter}\" #{flags} \"#{script_file.path}\"") super converge_by(nil) do # ensure script is unlinked at end of converge! unlink_script_file end end |
#flags ⇒ Object
70 71 72 |
# File 'lib/chef/provider/script.rb', line 70 def flags @new_resource.flags end |
#interpreter ⇒ Object
66 67 68 |
# File 'lib/chef/provider/script.rb', line 66 def interpreter @new_resource.interpreter end |
#script_file ⇒ Object
58 59 60 |
# File 'lib/chef/provider/script.rb', line 58 def script_file @script_file ||= Tempfile.open("chef-script") end |
#set_owner_and_group ⇒ Object
51 52 53 54 55 56 |
# File 'lib/chef/provider/script.rb', line 51 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 |
#unlink_script_file ⇒ Object
62 63 64 |
# File 'lib/chef/provider/script.rb', line 62 def unlink_script_file @script_file && @script_file.close! end |