class PackerFiles::Provision::ChefSolo

Public Class Methods

new() { |self| ... } click to toggle source

Constructor yields self

# File lib/PackerFiles/Provision/ChefSolo.rb, line 55
def initialize(&block)
   yield self if block_given?
   @type = 'chef-solo'
end

Public Instance Methods

convert_cookbook_paths() click to toggle source

Cookbook Path converter

# File lib/PackerFiles/Provision/ChefSolo.rb, line 40
def convert_cookbook_paths
   self.cookbook_paths.map {|p| File.absolute_path(p)}
end
convert_skip_to_boolean() click to toggle source

Boolean converter for skip_install

# File lib/PackerFiles/Provision/ChefSolo.rb, line 50
def convert_skip_to_boolean
   (self.skip_install.to_i > 0) ? true : false
end
convert_sudo_to_boolean() click to toggle source

Boolean converter for prevent_sudo

# File lib/PackerFiles/Provision/ChefSolo.rb, line 45
def convert_sudo_to_boolean
   (self.prevent_sudo.to_i > 0) ? true : false
end
convert_to_json() click to toggle source

JSON converter

# File lib/PackerFiles/Provision/ChefSolo.rb, line 30
def convert_to_json
   # Check if it is a string and if so parse it into JSON
   begin
      return JSON.parse(self.json)
   rescue JSON::ParserError => e
      return JSON.parse(File.read(self.json))
   end
end
to_hash(*args) click to toggle source

If chef-solo has to work, all the dependent cookbooks also needs to be found in one of the cookbook folders. So we need to intercept the to_hash call to extract cookbooks inside a .tar.gz bundle.

Calls superclass method
# File lib/PackerFiles/Provision/ChefSolo.rb, line 64
def to_hash(*args)
  
   # The Provisioner usually passes the OS class as it's first
   # argument
   os   = args[0]

   # Some cookbook paths are special in the sense, they are .tar.gz
   # bundles. The code fragment handles that special case.
   convert_cookbook_paths.each_with_index do |path, index|
      next if !path.end_with?('.tar.gz')
      temp   = Dir.mktmpdir('dep', os.OutDir) 
      helper = ChefSoloHelper.new(path)
      local  = helper.download_files(os.OutDir)
      helper.extract_files(temp, local)
      @cookbook_paths.push(temp)
   end

   # Remove all the cookbooks that end with .tar.gz
   @cookbook_paths.delete_if {|cb| cb.end_with?('.tar.gz')}

   # call back the original to_hash function.
   super
end