Class: ChefCookbookCopy

Inherits:
Chef::Handler
  • Object
show all
Defined in:
lib/chef-handler-cookbook-copy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = defaults) ⇒ ChefCookbookCopy

Returns a new instance of ChefCookbookCopy.



29
30
31
32
33
# File 'lib/chef-handler-cookbook-copy.rb', line 29

def initialize(options = defaults)
  @path = options[:path]
  @mode = options[:mode]
  @always_copy = options[:always_copy]
end

Instance Attribute Details

#always_copyObject (readonly)

Returns the value of attribute always_copy.



27
28
29
# File 'lib/chef-handler-cookbook-copy.rb', line 27

def always_copy
  @always_copy
end

#modeObject (readonly)

Returns the value of attribute mode.



27
28
29
# File 'lib/chef-handler-cookbook-copy.rb', line 27

def mode
  @mode
end

#pathObject (readonly)

Returns the value of attribute path.



27
28
29
# File 'lib/chef-handler-cookbook-copy.rb', line 27

def path
  @path
end

Instance Method Details

#copy_cookbooksObject



43
44
45
46
47
48
49
50
# File 'lib/chef-handler-cookbook-copy.rb', line 43

def copy_cookbooks
  cookbook_paths = Array(Chef::Config[:cookbook_path])
  cookbook_paths.each_with_index do |origin, index|
    dst = ::File.join(@path, "cookbooks-#{index}")
    FileUtils.mkdir_p(dst, :mode => @mode) if !Dir.exists?(dst)
    FileUtils.cp_r(origin, dst)
  end
end

#defaultsObject



35
36
37
38
39
40
41
# File 'lib/chef-handler-cookbook-copy.rb', line 35

def defaults
  return {
    :path => '/var/cache/chef/cookbooks',
    :mode => 0755,
    :always_copy => true
  }
end

#reportObject



52
53
54
55
56
57
# File 'lib/chef-handler-cookbook-copy.rb', line 52

def report
  if run_status.success? || @always_copy
    Chef::Log.info "Copying cookbooks to #{@path}"
    copy_cookbooks
  end
end