Class: Chef::Provider::Template
- Inherits:
-
File
- Object
- Chef::Provider
- File
- Chef::Provider::Template
- Defined in:
- lib/chef/provider/template.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
- #action_create ⇒ Object
- #content_matches? ⇒ Boolean
- #define_resource_requirements ⇒ Object
- #load_current_resource ⇒ Object
- #rendered(rendered_template) ⇒ Object
- #resource_cookbook ⇒ Object
- #template_finder ⇒ Object
- #template_location ⇒ Object
Methods included from Mixin::Template
Methods included from Mixin::Checksum
Methods included from Mixin::EnforceOwnershipAndPermissions
#access_controls, #enforce_ownership_and_permissions
Methods inherited from File
#action_create_if_missing, #action_delete, #action_touch, #backup, #compare_content, #deploy_tempfile, #diff_current, #diff_current_from_content, #is_binary?, #set_all_access_controls, #set_content, #setup_acl, #update_new_file_state, #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, #events, #initialize, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #set_updated_status, #whyrun_mode?, #whyrun_supported?
Methods included from DSL::Recipe
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_create ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/chef/provider/template.rb', line 51 def action_create render_with_context(template_location) do |rendered_template| rendered(rendered_template) if file_already_exists? && content_matches? Chef::Log.debug("#{@new_resource} content has not changed.") set_all_access_controls update_new_file_state(@new_resource.path) else description = [] = if file_already_exists? "update #{@current_resource} from #{short_cksum(@current_resource.checksum)} to #{short_cksum(@new_resource.checksum)}" else "create #{@new_resource}" end description << description << diff_current(rendered_template.path) converge_by(description) do backup FileUtils.cp(rendered_template.path, @new_resource.path) Chef::Log.info("#{@new_resource} updated content") access_controls.set_all! update_new_file_state(@new_resource.path) end end end end |
#content_matches? ⇒ Boolean
100 101 102 |
# File 'lib/chef/provider/template.rb', line 100 def content_matches? @current_resource.checksum == @new_resource.checksum end |
#define_resource_requirements ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/chef/provider/template.rb', line 40 def define_resource_requirements super requirements.assert(:create, :create_if_missing) do |a| a.assertion { ::File::exist?(template_location) } a. "Template source #{template_location} could not be found." a.whyrun "Template source #{template_location} does not exist. Assuming it would have been created." a.block_action! end end |
#load_current_resource ⇒ Object
35 36 37 38 |
# File 'lib/chef/provider/template.rb', line 35 def load_current_resource @current_resource = Chef::Resource::Template.new(@new_resource.name) super end |
#rendered(rendered_template) ⇒ Object
94 95 96 97 98 |
# File 'lib/chef/provider/template.rb', line 94 def rendered(rendered_template) @new_resource.checksum(checksum(rendered_template.path)) Chef::Log.debug("Current content's checksum: #{@current_resource.checksum}") Chef::Log.debug("Rendered content's checksum: #{@new_resource.checksum}") end |
#resource_cookbook ⇒ Object
90 91 92 |
# File 'lib/chef/provider/template.rb', line 90 def resource_cookbook @new_resource.cookbook || @new_resource.cookbook_name end |
#template_finder ⇒ Object
78 79 80 81 82 |
# File 'lib/chef/provider/template.rb', line 78 def template_finder @template_finder ||= begin TemplateFinder.new(run_context, cookbook_name, node) end end |
#template_location ⇒ Object
84 85 86 87 88 |
# File 'lib/chef/provider/template.rb', line 84 def template_location @template_file_cache_location ||= begin template_finder.find(@new_resource.source, :local => @new_resource.local, :cookbook => @new_resource.cookbook) end end |